#include <bits/stdc++.h>
using namespace std;
typedef long long lnt;
const lnt P = 1000000007;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n, m, s;
lnt PowMod(lnt x, int k) {
	lnt ret = 1;
	for (; k; k >>= 1, x = x*x%P)
		if (k&1) ret = ret*x%P;
	return ret;
}
lnt C(int n, int m) {
	lnt ret = 1;
	for (int i = 2; i <= m; i++)
		ret = ret*i%P;
	ret = PowMod(ret, P-2);
	for (int i = n; i > n-m; i--)
		ret = ret*i%P;
	return ret;
}
int main() {
	read(n), read(m);
	for (int i = 0, a; i < n; i++)
		read(a), s += a;
	return printf("%lld\n", C(n+m, n+s)), 0;
}

#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main() { 
    string n;
    cin >> n;
    int nlen = n.size(), res=-1;

    rep2(i, 1, 1<<nlen){
        int sum = 0;
        rep(j, nlen){
            if((i>>j) & 1){
                sum += n[j] - '0';
                // cout << sum << endl;
            }
        }
        if(sum%3==0){
            // cout << i << " " << sum << endl;
            res = max(res, __builtin_popcount(i));
        }
    }

    if(res == -1){
        cout << res << endl;
    }else{
        cout << nlen - res << endl;
    }
    return 0; 
}