#include <bits/stdc++.h>
using namespace std;
long long int n, m;
long long int modexp(long long int x, long long int p) {
  if (p == 1) return x % 1000000007;
  long long int t = ((x % 1000000007) * (x % 1000000007)) % 1000000007;
  if (p % 2)
    return ((x % 1000000007) * modexp(t, p / 2) % 1000000007) % 1000000007;
  else
    return modexp(t, p / 2) % 1000000007;
}
long long int modinv(long long int x) { return modexp(x, 1000000007 - 2); }
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int prob(long long int *s, long long int *t, long long int l) {
  if (l == 1) {
    if (*s == 0 && *t == 0)
      return ((m - 1) % 1000000007 * modinv(2 * m)) % 1000000007;
    else if (*s == 0)
      return ((m - *t) % 1000000007 * modinv(m)) % 1000000007;
    else if (*t == 0)
      return ((*s - 1) % 1000000007 * modinv(m)) % 1000000007;
    else if (*s <= *t)
      return 0;
    else if (*s > *t)
      return 1;
  } else if (l > 1) {
    if (*s == 0 && *t == 0)
      return ((m - 1) % 1000000007 * modinv(2 * m) +
              modinv(m) * prob(s + 1, t + 1, l - 1)) %
             1000000007;
    else if (*s == 0)
      return (((m - *t) % 1000000007 * modinv(m)) % 1000000007 +
              modinv(m) * prob(s + 1, t + 1, l - 1)) %
             1000000007;
    else if (*t == 0)
      return (((*s - 1) % 1000000007 * modinv(m)) % 1000000007 +
              modinv(m) * prob(s + 1, t + 1, l - 1)) %
             1000000007;
    else if (*s < *t)
      return 0;
    else if (*s == *t)
      return prob(s + 1, t + 1, l - 1);
    else if (*s > *t)
      return 1;
  }
}
int main() {
  cin >> n >> m;
  long long int s[n], t[n];
  for (long long int i = 0; i < n; i++) cin >> s[i];
  for (long long int i = 0; i < n; i++) cin >> t[i];
  cout << prob(s, t, n) << endl;
}
