#include <iostream>
using namespace std;
int main()
{
int n, c = 0;
cin >> n;
while (n != 495)
{
c++;
int a = n / 100, b = n / 10 % 10, c = n % 10;
if (a < b)
swap(a, b);
if (a < c)
swap(a, c);
if (b < c)
swap(b, c);
n = a * 100 + c - a - c * 100;
}
cout << c;
return 0;
}