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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import java.io.*;
import java.util.*;
import java.math.*;

public class fib
{
	static class F
	{
		BigInteger a, b, c, d;

		F()
		{
			a = d = BigInteger.ONE;
			b = c = BigInteger.ZERO;
		}

		F mult(F B, BigInteger mod)
		{
			F C = new F();
			C.a = (a.multiply(B.a).add(b.multiply(B.c))).mod(mod);
			C.b = (a.multiply(B.b).add(b.multiply(B.d))).mod(mod);
			C.c = (c.multiply(B.a).add(d.multiply(B.c))).mod(mod);
			C.d = (c.multiply(B.b).add(d.multiply(B.d))).mod(mod);
			return C;
		}

		F pow(BigInteger exp, BigInteger mod)
		{
			F X = new F();
			F A = this;
			while(!exp.equals(BigInteger.ZERO))
			{
				if (exp.mod(BigInteger.valueOf(2)).equals(BigInteger.ONE)) X = X.mult(A, mod);
				A = A.mult(A, mod);
				exp = exp.divide(BigInteger.valueOf(2));
			}
			return X;
		}
	}

	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		String s = scanner.next();
		int n = s.length();
		//System.out.println(n);
		if (n == 1)
		{
			int N = Integer.parseInt(s);
			int mod = 10;
			int a = 0, b = 1;
			int k = -1;
			boolean overMod = false;
			for (int i = 2; i <= 65; i++)
			{
				if (b + a > mod/10) overMod = true;
				int c = (b + a) % mod;
				if (N == c && overMod) 
				{
					k = i;
					break;
				}
				a = b;
				b = c;
			}
			if (k == -1) System.out.println("NIE");
			else System.out.println(k);
		}
		else if (n == 2)
		{
			int N = Integer.parseInt(s);
			int mod = 100;
			int a = 0, b = 1;
			int k = -1;
			boolean overMod = false;
			for (int i = 2; i <= 310; i++)
			{
				if (b + a > mod/10) overMod = true;
				int c = (b + a) % mod;
				if (N == c && overMod) 
				{
					k = i;
					break;
				}
				a = b;
				b = c;
			}
			if (k == -1) System.out.println("NIE");
			else System.out.println(k);
		}
		else if (n == 3)
		{
			int N = Integer.parseInt(s);
			int mod = 1000;
			int a = 0, b = 1;
			int k = -1;
			boolean overMod = false;
			for (int i = 2; i <= 1510; i++)
			{
				if (b + a > mod/10) overMod = true;
				int c = (b + a) % mod;
				if (N == c && overMod) 
				{
					k = i;
					break;
				}
				a = b;
				b = c;
			}
			if (k == -1) System.out.println("NIE");
			else System.out.println(k);
		}
		else
		{
			BigInteger N = new BigInteger(s);
			F A = new F();
			A.a = A.b = A.c = BigInteger.ONE;
			A.d = BigInteger.ZERO;
			BigInteger pattern = BigInteger.ZERO;
			BigInteger mod = BigInteger.ONE;
			BigInteger mult = BigInteger.ONE;
			BigInteger max = BigInteger.valueOf(2);
			BigInteger q = BigInteger.valueOf(1000);
			//BigInteger k = BigInteger.ZERO;
			int cnt = 0;
			Set<BigInteger> list1 = new HashSet<BigInteger>();
			list1.add(BigInteger.ZERO);
			Set<BigInteger> list2 = new HashSet<BigInteger>();
			while(n > 0)
			{
				/*
				if (n >= 3)
				{
					mult = mod.multiply(BigInteger.valueOf(3)).divide(BigInteger.valueOf(2));
					mod = mod.multiply(q);
					max = max.multiply(q);
					cnt += 3;
					n -= 3;
					pattern = new BigInteger(s.substring(s.length() - cnt));
					for (int i = 0; i <= 1600; i++)
					{
						for(BigInteger k: list1)
						{
							F B = A.pow(mult.multiply(BigInteger.valueOf(i)).add(k), mod);
							if (B.b.equals(pattern) && !A.pow(mult.multiply(BigInteger.valueOf(i)).add(k), mod.add(BigInteger.ONE)).b.equals(B.b))
							{
								k = k.add(mult.multiply(BigInteger.valueOf(i)));
								list2.add(k);
								//System.out.println(k);
								//break;
							}
						}
					}
					list1.clear();
					list1.addAll(list2);
					list2.clear();
				}
				else if (n == 2)
				{
					mult = mod.multiply(BigInteger.valueOf(3)).divide(BigInteger.valueOf(2));
					mod = mod.multiply(BigInteger.valueOf(100));
					max = max.multiply(BigInteger.valueOf(100));
					cnt += 2;
					n -= 2;
					pattern = new BigInteger(s.substring(s.length() - cnt));
					for (int i = 0; i <= 1600; i++)
					{
						for(BigInteger k: list1)
						{
							F B = A.pow(mult.multiply(BigInteger.valueOf(i)).add(k), mod);
							if (B.b.equals(pattern) && !A.pow(mult.multiply(BigInteger.valueOf(i)).add(k), mod.add(BigInteger.ONE)).b.equals(B.b))
							{
								k = k.add(mult.multiply(BigInteger.valueOf(i)));
								list2.add(k);
								//System.out.println(k);
								//break;
							}
						}
					}
					list1.clear();
					list1.addAll(list2);
					list2.clear();
				}
				*/
				//else if (n == 1)
				{
					mult = mod.multiply(BigInteger.valueOf(3)).divide(BigInteger.valueOf(2));
					mod = mod.multiply(BigInteger.valueOf(10));
					max = max.multiply(BigInteger.valueOf(10));
					cnt += 1;
					n -= 1;
					int mx = 0;
					if (cnt == 1) mx = 1600;
					else mx = 12;
					pattern = new BigInteger(s.substring(s.length() - cnt));
					for (int i = 0; i <= mx; i++)
					{
						//System.out.println(i);
						for(BigInteger k: list1)
						{
							//System.out.println(mult.multiply(BigInteger.valueOf(i)).add(k));
							F B = A.pow(mult.multiply(BigInteger.valueOf(i)).add(k), mod);
							//if (i == 1499) System.out.println(A.pow(mult.multiply(BigInteger.valueOf(i)).add(k), mod.add(BigInteger.ONE)).b);
							if (B.b.equals(pattern) && !A.pow(mult.multiply(BigInteger.valueOf(i)).add(k), mod.add(BigInteger.valueOf(1009))).b.equals(B.b))
							{
								k = k.add(mult.multiply(BigInteger.valueOf(i)));
								list2.add(k);
								//System.out.println("I" + i);
								//System.out.println(k);
								//break;
							}
						}
					}
					list1.clear();
					list1.addAll(list2);
					list2.clear();
				}
				//System.out.println(list1.size());
			}
			if (list1.size() == 0)  System.out.println("NIE");
			else System.out.println(list1.iterator().next());
		}
		
	}
}