usingnamespace std; constint mod = 5000007; #define ll long long ll ans, n, m, k[200], p[200], num[5000008], book[5000008];
ll qp(ll a, ll b){ ll base = a, res = 1; while (b > 0) { if (b & 1) { res *= base; } base *= base; b >>= 1; } return res; }
ll has(ll x){ ll res = x % mod; if (res < 0) res += mod; while (num[res] && book[res] != x) { res++; if (res == mod) res = 0; } return res; }
voidf(ll x, ll sum){ if (x > n / 2) { int p = has(sum); num[p]++; book[p] = sum; return; } for (int i = 1; i <= m; i++) { f(x + 1, sum + qp(i, p[x]) * k[x]); } }
voidf2(ll x, ll sum){ if (x > n) { ans += num[has(-sum)]; return; } for (int i = 1; i <= m; i++) { f2(x + 1, sum + qp(i, p[x]) * k[x]); } }
intmain(){ cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> k[i] >> p[i]; } f(1, 0); f2(n / 2 + 1, 0); cout << ans; return0; }