#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef complex<LD> CMP;

int gcd(int a, int b)
{
	while(a)
		swap(a, b%=a);
	return b;
}

class FruitTrees { public:
	int maxDist(int apple, int kiwi, int grape)
	{
		int best = 0;
		for(int k0=0; k0<kiwi; ++k0) {
			int ak = calc(apple, 0, kiwi, k0);
			for(int g0=0; g0<grape; ++g0)
				best = max(best, min(ak, min(calc(apple, 0, grape, g0), calc(kiwi, k0, grape, g0))));
		}
		return best;
	}

	int calc(int a, int a0, int b, int b0)
	{
		//int x = abs(b0-a0);
		int x = b0-a0;
		int g = gcd(a, b);
		return min(x%g, g-x%g);
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, FruitTrees().maxDist(apple, kiwi, grape));}
int main(){

CASE(0)
	int apple = 1; 
	int kiwi = 5; 
	int grape = 8; 
	int _ = 0; 
END
CASE(1)
	int apple = 3; 
	int kiwi = 3; 
	int grape = 6; 
	int _ = 1; 
END
CASE(2)
	int apple = 40; 
	int kiwi = 30; 
	int grape = 20; 
	int _ = 5; 
END
CASE(3)
	int apple = 899; 
	int kiwi = 1073; 
	int grape = 1147; 
	int _ = 14; 
END
CASE(4)
	int apple = 2000; 
	int kiwi = 2000; 
	int grape = 2000; 
	int _ = 666; 
END
CASE(5)
	int apple = 100; 
	int kiwi = 36; 
	int grape = 225; 
	int _ = -1; 
END
/*
CASE(6)
	int apple = ; 
	int kiwi = ; 
	int grape = ; 
	int _ = ; 
END
*/
}
// END CUT HERE
