#include <bits/stdc++.h>
using namespace std;

long long gcd_ll(long long a, long long b) {
    while (b != 0) {
        long long t = a % b;
        a = b;
        b = t;
    }
    return a;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    cout.tie(0);
    freopen("BAI1.INP", "r", stdin);
    freopen("BAI1.OUT", "w", stdout);

    long long a, b, n;
    cin >> a >> b >> n;

    long long g = gcd_ll(a, b);

    // Tính BCNN can than tranh tran so
    long long lcm = a / g;
    // Kiem tra tràn khi nhân
    if (lcm > LLONG_MAX / b) {
        cout << -1;
        return 0;
    }
    lcm *= b;

    long long d;
    if (lcm > n) {
        d = -1;
    } else {
        d = (n / lcm) * lcm;
        if (d == 0) d = -1;
    }

    cout << d;
    return 0;
}

