1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, PLL> PP;
typedef unsigned int ui;
const int mod = 1e9+7;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const ll INF = 1e18;


inline ll pomnoz(ull a, ull b, ull mod) {
	a %= mod; b %= mod;
	ull ret = 0;
	while (b) {
		if (b & 1) ret += a;
		while (ret >= mod) ret -= mod;
		a<<=1;
		while (a >= mod) a -= mod;
		b>>=1;
	}
	return ret;
}

inline PP multiply(PP a, PP b, ll mod) {
	PP help; 
	help.e1.e1 = (pomnoz(a.e1.e1, b.e1.e1, mod) + pomnoz(a.e1.e2, b.e2.e1, mod))%mod;
	help.e2.e2 = (pomnoz(a.e2.e2, b.e2.e2, mod) + pomnoz(a.e2.e1, b.e1.e2, mod))%mod;
	
	help.e1.e2 = (pomnoz(a.e1.e1, b.e1.e2, mod) + pomnoz(a.e1.e2, b.e2.e2, mod))%mod;
	help.e2.e1 = (pomnoz(a.e2.e1, b.e1.e1, mod) + pomnoz(a.e2.e2, b.e2.e1, mod))%mod;
	return help;
}

inline ll fib(ll pot, ll mod)
{
	PP start = mp(mp(1, 0), mp(0, 0)); PP a = mp(mp(1, 1), mp(1, 0));
	if (pot == 0) return 0;
	--pot;
	while (pot) {
		if (pot & 1) start = multiply(start, a, mod);
		a = multiply(a, a, mod);
		pot >>= 1;
	}
	return start.e1.e1 % mod;
}
inline int dl(ll x) {
	int ret =0 ;
	while (x) x /= 10, ++ret;
	return ret;
}
ll reszty[20], cykle[20];
ll n;
int DDD(ll k)
{
	if (k > 88) return 100;
	else return dl(fib(k, INF));
}
bool check(ll k, ll mod)
{
	ll liczba = fib(k, mod) % mod;
	if (liczba == reszty[dl(mod) - 1]) return true;
	return false;
}
ll POT[20];
string s;

ll liczbuj(string x)
{
	int len = x.length();
	ll r = 0;
	for (int i=0; i<len; ++i) r = (r << 1) + (r << 3) + x[i] - '0';
	return r;
}
int main()
{
	POT[0] = 1;
	cin >> s;
	int sz = s.length();
	n = liczbuj(s);
	ll pot = 1;
	for (int i=1; i<=18; ++i)
	{
		pot *= 10;
		POT[i] = pot;
		reszty[i] = (n % pot);
	}

	cykle[1] = 60;
	cykle[2] = 300;
	cykle[3] = 1500;
	for (int i=4; i<=18; ++i) cykle[i] = cykle[i-1] * 10;
	vector <ll> akt;
	akt.clear();
	for (int i=1; i<=60; ++i) 
	  if (check(i, 10)) akt.push_back(i);
	
	if (sz == 1)
	{
		if (akt.size() == 0) puts("NIE"), exit(0);
		else printf("150000000000000000000%lld", akt[0]), exit(0);
	}
	for (int i=2; i<=sz; ++i) 
	{
		ll ile = cykle[i] / cykle[i-1];
		vector <ll> nowy;
		nowy.clear();
		for (ui j=0; j<akt.size(); ++j)
		{
			ll N = akt[j];
			for (ll K = 0; K < ile; ++K)
			  if (check(K * cykle[i - 1] + N, POT[i]))
			  {	  
				  if (i == sz) 
				  {
					  ll R = K * cykle[i-1] + N;
					  printf("150000000000000000000%lld", R), exit(0);
				  }
				  else nowy.pb(K * cykle[i - 1] + N);
			  }
		}
		akt.clear();
		for (ui i=0; i<nowy.size(); ++i) akt.pb(nowy[i]);
	}
	puts("NIE");
}