#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(ll x=pow(10,7)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N, X; cin >> N >> X;
  ll V[N], P[N]; rep(i,N) cin >> V[i] >> P[i];

  X *= 100;
  ll sum = 0;
  rep(i,N) {
    sum += V[i] * P[i];
    if (sum>X) {
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;


const int N = 2e5 + 5, mod = 1e9 + 7;
char s[N];
int a[N], k;
int add (int a, int b) {
	return ((a += b) >= mod) ? (a - mod) : a;
}
int dp[N][20], K;
int f (int l, int k) {
	if (~dp[l][k]) return dp[l][k];
	if (l == 0) return k == K;
	dp[l][k] = (ll)k * f(l - 1, k) % mod;
	if (k)
		dp[l][k] = add(dp[l][k], (ll)f(l - 1, k + 1) * (16 - k) % mod);
	return dp[l][k];
}
int main() {
	memset (dp, -1, sizeof (dp));
	cin >> (s + 1) >> K;
	int len = strlen(s + 1);
	for (int i = 1; i <= len; ++i) {
		if (isdigit(s[i])) a[i] = s[i] - '0';
		else a[i] = s[i] - 'A' + 10;
	}
	
	int ans = 0;
	for (int i = len; i >= 2; --i) {
		for (int j = 1; j < 16; ++j) ans += f (len - i, 1), ans %= mod;
		ans %= mod;
	}
	
//	cerr << ans << '\n';
	int st = 0;
	for (int i = 1; i <= len; ++i) {
		for (int j = ((i == 1) ? 1 : 0); j < a[i]; ++j) {
			int newst = st | (1 << j), cnt = __builtin_popcount(newst);
		//	cerr << len - i << " " << cnt << ":" << f(len - i, cnt) << '\n';
			ans = add(ans, f(len - i, cnt));
		}
		st |= (1 << a[i]);
	}
	if (__builtin_popcount(st) == K) ans = add(ans, 1);
	cout << ans << '\n';
	return 0;
}

