#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define pb push_back 
#define eb emplace_back 
#define fi first
#define se second
#define all(x) x.begin() , x.end()
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>

const static int INF = 1001001001;
const static ll LINF = 1001001001001001001LL;
const static lld PI = 3.1415926535897932384626L;
const static int MOD = 1000000009;
//const static int MOD = 998244353;

template < typename T > T gcd (T a , T b) { if (a < b) swap(a , b); if (a % b == 0) return b; else return gcd (b , a % b); }
template < typename T > T lcm (T a , T b) { return (a / gcd (a , b) * b); }
template < typename T > bool chmin (T &a , T b) { if (a > b) { a = b; return true; } else { return false; } }
template < typename T > bool chmax (T &a , T b) { if (a < b) { a = b; return true; } else { return false; } }
int keta (ll x) { int ret = 0; while(x) { ret++; x /= 10; } return ret; }
inline int in () { int x; scanf("%d" , &x); return x; }
inline ll lin () { ll x; scanf("%lld" , &x); return x; }
inline string sin () { string s; cin >> s; return s; }

void io_setup () {
    cout << fixed << setprecision(15);
    //cin.tie(0);
    //ios::sync_with_stdio(false);
}

bool is_prime (ll x) {
    if (x == 2 || x == 3 || x == 5 || x == 7) {
        return true;
    }
    for (ll i = 3; i * i <= x; i++) {
        if (x % i == 0) {
            return false;
        }
    }
    return true;
}

/*
vb prime_table(2020202 , true);
void prime () {
    prime_table[0] = false;
    prime_table[1] = false;
    for (int i = 2; i < 2020202; i++) {
        for(int j = i + i; j < 2020202; j += i) {
            prime_table[j] = false;
        }
    }
}
*/

/*
//memo
v.erase(unique(all(v)), v.end());
*/

void solve() {
    /*
    int H = in();
    int N = in();
    vi A(n) , B(n);
    rep (i,n) {
        A[i] = in();
        B[i] = in();
    }
    */
    string s;
    cin >> s;
    vi cnt(3 , 0);
    rep(i,s.size()) {
        int now = int(s[i] - '0');
        now %= 3;
        cnt[now]++;
    }
    int sum = 0;
    rep(i,3)  sum += cnt[i] * i; 
    if (sum % 3 == 0 && (cnt[0] > 0 || cnt[1] > 0 || cnt[2] > 0)) {
        cout << 0 << endl;
        return;
    }
    
    if (sum % 3 == 1) {
        if (cnt[1] >= 1) {
            cnt[1] -= 1;
            int sum2 = 0;
            rep(i,3) sum2 += cnt[i] * i;
            if (sum2 % 3 == 0 && (cnt[0] > 0 || cnt[1] > 0 || cnt[2] > 0)) {
                cout << 1 << endl;
                return;
            }
        }
        if (cnt[2] >= 2) {
            cnt[2] -= 2;
            int sum2 = 0;
            rep(i,3) sum2 += cnt[i] * i;
            if (sum2 % 3 == 0 && (cnt[0] > 0 || cnt[1] > 0 || cnt[2] > 0)) {
                cout << 2 << endl;
                return;
            }
        }
        cout << -1 << endl;
        return;
    }
    
    if (sum % 3 == 2) {
        if (cnt[2] >= 1) {
            cnt[2] -= 1;
            int sum2 = 0;
            rep(i,3) sum2 += cnt[i] * i;
            if (sum2 % 3 == 0 && (cnt[0] > 0 || cnt[1] > 0 || cnt[2] > 0)) {
                cout << 1 << endl;
                return;
            }
        }
        if (cnt[1] >= 2) {
            cnt[1] -= 2;
            int sum2 = 0;
            rep(i,3) sum2 += cnt[i] * i;
            if (sum2 % 3 == 0 && (cnt[0] > 0 || cnt[1] > 0 || cnt[2] > 0)) {
                cout << 2 << endl;
                return;
            }
        }
        cout << -1 << endl;
        return;
    }
    return;
}

int main () {
    io_setup();
    //prime();
    solve();
    return 0;
}



//#pragma GCC optimize(2)
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#define DEBUG
#define INF 0x3f3f3f3f3f3f3f3f
#define mod 1000000007
#define PI 3.14159265358979323846
#define Base 23333333
//#define set unordered_set
//#define map unordered_map
#define int long long
#define LL long long
#define NO	cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define mst(x) memset(x,0,sizeof(x))
#define debug(x) cout<<"DEBUG:"<<x<<endl
//#define int unsigned long long
using namespace std;
//#define scanf scanf_s

//#define max(a,b) ((a) > (b) ? (a) : (b))
//#define min(a,b) ((a) < (b) ? (a) : (b))
inline int gcd(int a, int b) { return b > 0 ? gcd(b, a%b) : a; }
inline int lcm(int a, int b) { return a * b / gcd(a, b); }
inline int qpow(int a, int n) { int ans = 1;	while (n) { if (n & 1) { ans *= a; }a *= a; n >>= 1; }return ans; }
/*
#define read() _read()
#define cout fout
#define cin fin
ifstream fin("in.txt");fstream fout("out.txt");
int _read() {	int tmp;	fin >> tmp;	return tmp;}
*/
inline int read() { int x = 0, f = 1;	char ch = getchar();	while (ch<'0' || ch>'9') { if (ch == '-') { f = -1; }		ch = getchar(); }	while (ch >= '0'&&ch <= '9') { x = 10 * x + ch - '0';		ch = getchar(); }	return x * f; }

const int maxnum = 100000005;

int f[maxnum];



signed main()
{
	int n = read(), x = 100*read();
	int ans = -1;
	for (int i = 1; i <= n; i++) {
		int a = read(), b = read();
		x -= a * b;
		if (x < 0) {
			ans = i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}




