#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int main(){
  char s[5];
  while(scanf("%s",s),strcmp(s,"0000")){
    bool f = true;
    for(int i=0;i<3;i++)f &= (s[i]==s[i+1]);
    if(f){ printf("NA\n"); continue; }

    int cnt = 0;
    while(strcmp(s,"6174")){
      sort(s,s+4);
      int S = atoi(s);
      reverse(s,s+4);
      int L = atoi(s);
      char N[5]; sprintf(N,"%04d",L-S);
      for(int i=0;i<4;i++)s[i] = N[i];
      cnt++;
    }
    printf("%d\n",cnt);
  }
}
      