#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>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class MagicalSource { public:
	long long calculate(long long x) 
	{
		LL d[] = {
			1LL,
			11LL,
			111LL,
			1111LL,
			11111LL,
			111111LL,
			1111111LL,
			11111111LL,
			111111111LL,
			1111111111LL,
			11111111111LL,
			111111111111LL,
			1111111111111LL,
		};
		int N = sizeof(d) / sizeof(*d);
		assert( d[N-1] > 1000000000000LL );
		for(int i=N-1; i>=0; --i)
			if( x%d[i] == 0 )
				return x/d[i];
		return x; // unreachable
	}
};

// 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 long long& Expected, const long long& 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(_, MagicalSource().calculate(x));}
int main(){

CASE(0)
	long long x = 1371110974LL; 
	long long _ = 1234LL; 
END
CASE(1)
	long long x = 111111LL; 
	long long _ = 1LL; 
END
CASE(2)
	long long x = 10989LL; 
	long long _ = 99LL; 
END
CASE(3)
	long long x = 120LL; 
	long long _ = 120LL; 
END
CASE(4)
	long long x = 109999999989LL; 
	long long _ = 99LL; 
END
CASE(5)
	long long x = 1LL; 
	long long _ = 1LL; 
END
CASE(6)
	long long x = 1000000000000LL; 
	long long _ = 1000000000000LL; 
END
CASE(7)
	long long x = 111111111111LL; 
	long long _ = 1LL; 
END
CASE(8)
	long long x = 123456654321LL; 
	long long _ = 111111LL; 
END
CASE(9)
	long long x = 12222221LL; 
	long long _ = 11LL; 
END

}
// END CUT HERE
