OI X - kaf

// https://szkopul.edu.pl/problemset/problem/1mRVaDVJ8FN2x69FUiYf89yt/site/?key=statement

#include <bits/stdc++.h>

// #define GARY_DBG
#define GARY_LIB

constexpr int sizik = 1000 * 1001;

#define ar std::array

typedef std::vector<std::vector<int>> _kra;

class BigInt {
private:
    std::vector<int> digits;

    void trim() {
        while (digits.size() > 1 && digits.back() == 0) {
            digits.pop_back();
        }
    }

public:
    BigInt() { digits.push_back(0); }

    BigInt(long long n) {
        if (n == 0) digits.push_back(0);
        while (n > 0) {
            digits.push_back(n % 10);
            n /= 10;
        }
    }

    BigInt(std::string s) {
        if (s.empty()) {
            digits.push_back(0);
        } else {
            for (int i = s.length() - 1; i >= 0; i--) {
                if (!isdigit(s[i])) throw std::invalid_argument("String must only contain digits");
                digits.push_back(s[i] - '0');
            }
            trim();
        }
    }

    std::string toString() const {
        if (digits.empty()) return "0";
        std::string s = "";
        for (int i = digits.size() - 1; i >= 0; i--) {
            s += std::to_string(digits[i]);
        }
        return s;
    }

    bool operator==(const BigInt& other) const { return digits == other.digits; }

    bool operator!=(const BigInt& other) const { return !(*this == other); }

    bool operator<(const BigInt& other) const {
        if (digits.size() != other.digits.size()) return digits.size() < other.digits.size();
        for (int i = digits.size() - 1; i >= 0; i--) {
            if (digits[i] != other.digits[i]) return digits[i] < other.digits[i];
        }
        return false;
    }

    bool operator>(const BigInt& other) const { return other < *this; }
    bool operator<=(const BigInt& other) const { return !(*this > other); }
    bool operator>=(const BigInt& other) const { return !(*this < other); }

    bool isEven() const {
        if (digits.empty()) return true;
        return digits[0] % 2 == 0;
    }

    bool isZero() const { return digits.size() == 1 && digits[0] == 0; }

    void divideBy2() {
        int remainder = 0;
        for (int i = digits.size() - 1; i >= 0; i--) {
            int cur = digits[i] + remainder * 10;
            digits[i] = cur / 2;
            remainder = cur % 2;
        }
        trim();
    }

    void multiplyBy2() {
        int carry = 0;
        for (size_t i = 0; i < digits.size() || carry; ++i) {
            if (i == digits.size()) digits.push_back(0);
            long long current = digits[i] * 2 + carry;
            digits[i] = current % 10;
            carry = current / 10;
        }
    }

    BigInt operator+(const BigInt& other) const {
        BigInt res;
        res.digits.clear();
        int carry = 0;
        size_t n = std::max(digits.size(), other.digits.size());

        for (size_t i = 0; i < n || carry; ++i) {
            int sum = carry + (i < digits.size() ? digits[i] : 0) + (i < other.digits.size() ? other.digits[i] : 0);
            res.digits.push_back(sum % 10);
            carry = sum / 10;
        }
        return res;
    }

    BigInt operator-(const BigInt& other) const {
        if (*this < other) {
            throw std::invalid_argument("Result would be negative (not supported for GCD logic)");
        }
        BigInt res = *this;
        int borrow = 0;
        for (size_t i = 0; i < other.digits.size() || borrow; ++i) {
            int sub = res.digits[i] - borrow - (i < other.digits.size() ? other.digits[i] : 0);
            if (sub < 0) {
                sub += 10;
                borrow = 1;
            } else {
                borrow = 0;
            }
            res.digits[i] = sub;
        }
        res.trim();
        return res;
    }
};

BigInt gcd(BigInt u, BigInt v) {
    if (u.isZero()) return v;
    if (v.isZero()) return u;

    int shift = 0;
    while (u.isEven() && v.isEven()) {
        u.divideBy2();
        v.divideBy2();
        shift++;
    }

    while (u.isEven()) {
        u.divideBy2();
    }

    while (!v.isZero()) {
        while (v.isEven()) {
            v.divideBy2();
        }

        if (u > v) {
            std::swap(u, v);
        }

        v = v - u;
    }

    for (int i = 0; i < shift; i++) {
        u.multiplyBy2();
    }

    return u;
}

void solve() {
    std::string n_str, k_str, l_str;
    std::cin >> n_str >> k_str >> l_str;

    BigInt n(n_str), k(k_str), l(l_str);

    if (k > l) {
        std::swap(k, l);
    }

    auto G = gcd(k, l);

    BigInt A("0");
    if (n >= l + k - G) {
        A = G;
    } else {
        BigInt B = n - l;
        A = k - B;
    }

    std::string ans = A.toString();

    std::cout << ans << '\n';
}

int32_t main() {
#ifndef GARY_DBG
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);
#endif

    int t = 1;
    // std::cin >> t;

    for (; t > 0; t--) {
        solve();
    }

    return 0;
}