#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int a;
  while(cin >> a) {
    if(a == -1) return 0;
    string ans = "0";
    rep(i, 0, a) {
      int f = 0;
      dep(j, ans.length() - 1, 0) {
        if(ans[j] == '3') {
          ans[j] = '0';
          if(j == 0) {
            ans = "1" + ans;
            break;
          }
        }else {
          if(f) break;
          ans[j]++;
          break;
        }
      }
    }
    cout << ans << endl;
  }
}