#include <iostream>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
void Code_By_Mohamed_Khaled() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}
ll Sum_of_range(ll l, ll r) {
    if (l > r) return 0;
    return r * (r + 1) / 2 - l * (l - 1) / 2;
}
ll mod=1e9+7;
ll add(ll a, ll b) {return ((b % mod) + (a % mod)) % mod;}
ll mul(ll a, ll b) {return ((b % mod) * (a % mod)) % mod;}
int main() {
    Code_By_Mohamed_Khaled();
    // (A+B)%C=D           if D>=C the no solution
    // i have two test cases  A+B==D  or A+B==D+C  then get A from to equations and minimize answer
    // if A==0 A should be positive then A=C
    long long b,c,d;cin>>b>>c>>d;
    if (d>=c) {
        cout<<-1;
        return 0;
    }
    long long a=(d-b+c)%c;
    if (a==0)cout<<c;
    else cout<<a;
    return 0;
}