// Author: Simon Gog
#include <iostream>
#include <fstream>
#include <vector>
#include <cassert>

using namespace std;

#define in cin

int main() {
	int a;
//	ifstream in("generate.in");
	while(in>>a && a){
		assert(a<10000);
		vector<int> occ(10000);
		int res = 0;
		while(!occ[a]){
			occ[a] = 1;
			a = ((a*a)/100)%10000;
			++res;
		}
		cout << res << endl;
	}
	return 0;
}
