#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
const long long inf = 1e18 + 10;
long long n, m, s1[maxn], s2[maxn];
long long dpequal[maxn], dplarge[maxn], mod = 1e9 + 7;
long long inv(long long a) {
  long long mode = 1e9 + 7;
  long long b = 1e9 + 5;
  long long sum = 1;
  while (b) {
    if (b & 1) {
      sum = (sum * a) % mode;
      b--;
    }
    b /= 2;
    a = a * a % mode;
  }
  return sum;
}
long long euqal_(long long x, long long y) {
  if (x == 0 || y == 0)
    return inv(m);
  else
    return x == y;
}
long long large(long long x, long long y) {
  if (x == 0 && y == 0)
    return (m - 1) * inv(2 * m) % mod;
  else if (x == 0)
    return (m - y) * inv(m) % mod;
  else if (y == 0)
    return (x - 1) * inv(m) % mod;
  else
    return x > y;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%lld", &s1[i]);
  for (int i = 1; i <= n; i++) scanf("%lld", &s2[i]);
  dpequal[0] = 1;
  dplarge[0] = 0;
  for (int i = 1; i <= n; i++) {
    long long l = large(s1[i], s2[i]), e = euqal_(s1[i], s2[i]);
    dpequal[i] = dpequal[i - 1] * e % mod;
    dplarge[i] = (dpequal[i - 1] * l % mod + dplarge[i - 1] % mod) % mod;
  }
  cout << dplarge[n] << endl;
}
