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
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<climits>
using namespace std;
typedef long long ll;

const ll big=15*1000LL*1000LL*1000LL*1000LL*1000LL*100LL;
class matrix
{
	public: 
	vector<vector<ll> > table;
	matrix(ll a=0,ll b=0,ll c=0,ll d=0):table(2,vector<ll>(2))
	{
		table[0][0]=a;
		table[0][1]=b;
		table[1][0]=c;
		table[1][1]=d;
	}
	vector<ll>& operator[](int x)
	{
		return this->table[x];
	}
	
};
ll fastMultiply(ll a,ll k,ll m)
{
	if(k==0)
		return 0;
	if(k==1)
		return a;
	if(k%2==1)
		return (fastMultiply(a,k-1,m)+a)%m;
	ll ee=fastMultiply(a,k/2,m);
	return (ee+ee)%m;
}
matrix multiply(matrix A,matrix B,ll m)
{
	
	return matrix(
	(fastMultiply(A[0][0],B[0][0],m)+fastMultiply(A[0][1],B[1][0],m))%m,
	(fastMultiply(A[0][0],B[0][1],m)+fastMultiply(A[0][1],B[1][1],m))%m,
	(fastMultiply(A[1][0],B[0][0],m)+fastMultiply(A[1][1],B[1][0],m))%m,
	(fastMultiply(A[1][1],B[1][1],m)+fastMultiply(A[1][0],B[0][1],m))%m);
}
ostream& operator<<(ostream& s,matrix A)
{
	for(auto i:A.table)
	{
		for(auto j:i)
			cout<<j<<' ';
		cout<<endl;
	}
	return s;
}
matrix power(matrix A,ll k,ll m)
{
	if(k==0)
		return matrix(1,0,0,1);
	if(k==1)
		return A;
	if(k%2==1)
		return multiply(A,power(A,k-1,m),m);
	matrix ee=power(A,k/2,m);
	return multiply(ee,ee,m);
}
ll fib(ll n,ll m=1000)
{
	matrix A(1,1,1,0);
	return power(A,n-1,m)[0][0];
}
ll powerOfTen(ll x)
{
	if(x==0)
		return 1;
	else
		return 10*powerOfTen(x-1);
}
ll minimalInterval(int x)
{
	if(x==0)
		return 1;
	if(x==1)
		return 60;
	if(x==2)
		return 300;
	return 15*powerOfTen(x-1);
	
}
int digits[30];
int desiredLength;
ll isWorking(int pointer,ll starter)
{
	if(pointer==desiredLength)
	{
		return starter;
	}
	ll myInterval=minimalInterval(pointer+1);
	ll lowerInterval=minimalInterval(pointer);
	ll myPower=powerOfTen(pointer);
	for(ll i=starter;i<=myInterval;i+=lowerInterval)
	{
		ll now=fib(i,myPower*10);
		if((now/myPower)==digits[pointer])
		{
			ll result=isWorking(pointer+1,i);
			if(result!=-1)
				return result;
		}
	}
	return -1;
}
int main()
{
		string S;
		cin>>S;
		desiredLength=S.length();
		for(unsigned i=0;i<S.length();i++)
		{
			digits[i]=S[S.length()-1-i]-'0';
		}
		ll result=isWorking(0,0);
		if(result==-1)
		{
			cout<<"NIE"<<endl;
			return 0;
		}
		cout<<result+big<<endl;
}