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

int main()
{
    ll x; cin >> x;
    cout << 100 - (x%100) << endl;
    return 0;
}

#include <bits/stdc++.h>

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
using ll = long long;
const int MOD = 1000000007;
const int INF = 2147483647;

int main() {
    FAST;

    int i, s = 0, l = 0, ans = 0;
    ll m;
    cin >> m;

    vector<int> d(3,0);
    while (m) {
        int t = (m % 10) % 3;

        ++l;
        s += t;
        ++d[t];

        m /= 10;
    }

    ans = s % 3;
    if (ans == 1) {
        if ((l > 1) && (d[1] >= 1)) {}
            else if ((l > 2) && (d[2] >= 2)) { ans = 2; }
            else ans = -1;
    } else if (ans == 2) {
        if ((l > 1) && (d[2] >= 1)) { ans = 1; }
            else if ((l > 2) && (d[1] >= 2)) {}
            else ans = -1;
    }

    cout << ans;

    return 0;
}
