//Jakub Staroń
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>

#ifdef COMPILING_HOME
#define DEBUG_MODE
#endif

using namespace std;

typedef char int8;
typedef unsigned char uint8;
typedef short int int16;
typedef unsigned short int uint16;
typedef int int32;
typedef unsigned int uint32;
typedef long long int64;
typedef unsigned long long uint64;

typedef std::pair<int32,int32> int32_pair;
typedef std::pair<uint32, uint32> uint32_pair;
typedef std::pair<int64,int64> int64_pair;
typedef std::pair<uint64,uint64> uint64_pair;

typedef std::vector<bool> bit_vector;

#ifdef DEBUG_MODE
#define debug_print(x) cerr << #x << " = " << x << endl
#define print_line cerr << "Line " << __LINE__ << endl
#include <cassert>
#else
#define debug_print(x)
#define print_line
#define assert(x)
#endif

#define rep(i, x) for(uint32 i = 0 ; i < (x) ; i++)
#define for_range(i, begin, end) for(auto i = (begin) ; i != (end) ; ++i )
#define all(c) (c).begin(),(c).end()
#define sort_all(x) sort( all(x) )
#define divide(a, b) ( ( (b)%(a) ) == 0 )
#define mp(x, y) make_pair(x,y)
#define pb(x) push_back(x)

#define sig(x) ( (x) == 0 ? 0 : ( (x) < 0 ? -1 : 1 ) )

const double epsilon = 1e-5;

template<class T>
void unique(std::vector<T>& v) {
	sort_all(v);
	v.resize( std::unique(all(v)) - v.begin() );
}

ostream& newline(ostream& str) {
	str.put('\n');
	return str;
}

template<typename T1, typename T2>
istream& operator>>(istream& stream, std::pair<T1, T2>& pair) {
	stream >> pair.first >> pair.second;
	return stream;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& stream, const std::pair<T1, T2>& pair) {
#ifdef DEBUG_MODE
	stream << "(" << pair.first << ", " << pair.second << ")";
#else
	stream << pair.first << ' ' << pair.second;
#endif
	return stream;
}

template<class T>
inline pair<T,T> operator+(const pair<T,T>& a, const pair<T,T>& b) {
	return pair<T,T>(a.first + b.first, a.second + b.second);
}

template<class T>
inline pair<T,T> operator-(const pair<T,T>& a, const pair<T,T>& b) {
	return pair<T,T>(a.first - b.first, a.second - b.second);
}

template<class T>
ostream& operator<<(ostream& str, const vector<T>& v) {
	if(!v.empty())	{
		for(int32 i = 0 ; i + 1 < v.size() ; i++)		
			str << v[i] << ' ';		
		str << v.back();
	}
	return str;
}

uint64 safe_multiply(uint64 a, uint64 b, uint64 modulo) {
  if (a == 0 || b == 0)
    return 0;

  if (a > b)
    swap(a, b);

  uint64 result = 0;
  while (a > 0) {
    if (divide(2, a)) {
      b = (b + b) % modulo;
    }
    else {
      result += b;
      result %= modulo;
      b = (b + b) % modulo;
    }

    a /= 2;
  }

  return result;
}

uint64 fibb_t[40] = {0, 1, 1, 2, 3, 5, 8, 13,
                        21, 34, 55, 89, 144, 233, 377, 610, 987, 1597,
                        2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418,
                        317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817,
                        39088169, 63245986
};

uint64_pair Fibonacci_pair(uint64 n, uint64 modulo) {
  if (n < 3) {
    return uint64_pair(fibb_t[n - 1], fibb_t[n]);
  }
  else {
    uint64_pair pair = Fibonacci_pair(n / 2, modulo);

    /**
     * k = n/2
     *
     * pair.first - F_k-1
     * pair.second - F_k
     *
     * A - F_2k-1
     * B - F_2k
     */
    uint64 A = (safe_multiply(pair.first, pair.first, modulo) +
                safe_multiply(pair.second, pair.second, modulo)) % modulo;

    uint64 B = (2 * pair.first + pair.second) % modulo;
    B = safe_multiply(B, pair.second, modulo);

    // if n = 2k + 1 one more step
    if (!divide(2, n)) {
      uint64 C = (A + B) % modulo;
      A = B;
      B = C;
    }

    return uint64_pair(A, B);
  }
}

uint64 Fibonacci(uint64 n, uint64 modulo) {
  if (n < 3)
    return fibb_t[n] % modulo;
  else
    return Fibonacci_pair(n, modulo).second;
}

class Application {
public:
	Application() {
    cycle_length.push_back(1);
    cycle_length.push_back(60);
    cycle_length.push_back(300);

    uint64 cycle = 100;
    for_range(i, 3, 20) {
      cycle_length.push_back(cycle * 15);
      cycle *= 10;
    }
	}

	void Run() {
		WczytajDane();

    vector<uint64> solutions;
    uint64 N = numbers.back();
    numbers.pop_back();

    rep(i, cycle_length[1])
      if (Fibonacci(i, 10) == N)
        solutions.push_back(i);

    uint32 suffix_length = 1;
    uint64 modulo = 10;
    while (!numbers.empty() && !solutions.empty()) {
      N = N + modulo * numbers.back();
      suffix_length++;
      modulo *= 10;
     // debug_print(suffix_length);
      //debug_print(N);
      //debug_print(modulo);
     // debug_print(solutions);

      numbers.pop_back();

      vector<uint64> new_solutions;

      for (uint64 solution : solutions) {
        // ponieważ później cykle rosną co najwyżej razy 10
        rep(j, 10) {
          uint64 potential_solution = solution + (uint64)j * cycle_length[suffix_length - 1];
          if (Fibonacci(potential_solution, modulo) == N) {
            new_solutions.push_back(potential_solution);
          }
        }
      }

      unique(new_solutions);
      swap(solutions, new_solutions);
    }

    if (solutions.empty()) {
      cout << "NIE" << endl;
    }
    else {
      uint64 solution = (solutions.front() + cycle_length[suffix_length]);
      cout << solution << endl;
    }
	}

	void WczytajDane() {
    string text;
    cin >> text;
    for (char c : text)
      numbers.push_back(c - '0');
	}

	vector<uint64> numbers;
  vector<uint64> cycle_length;
};


int main() {
	ios::sync_with_stdio(0);
  Application application;
  application.Run();
	return 0;
}