#include <iostream>
#include <vector>
using namespace std;
int findBin(vector<int>& arr,int target){
int l=0,r=arr.size()-1;
int mid;
while(l<=r){
mid=(l+r)/2;
if(arr[mid]==target) return mid;
if(target<arr[mid]){
r=mid-1;
}
else{
l=mid+1;
}
}
return -1;
}
int main()
{
int arr[]={1,2,4,5,7,8,10,12,13,18,24,29,54,321,777,785,988};
vector<int> arra(arr,arr+17);
int num;
while(1){
cin>>num;
if(num==-1)return 0;
cout<<findBin(arra,num)<<endl;
}
}