#include <iostream>
 
using namespace std;
 
int main() {
    int candy = 0;
       
    while (true){
    cin >> candy;
    if (candy == -1) {
        break;
    }
     
    cout << candy % 39 << endl;
     
    }
}
 
 