#include <bits/stdc++.h>
using namespace std;
const long long mo = 1e9 + 7;
template <typename _T>
void read(_T &x) {
  _T f = 1;
  x = 0;
  char s = getchar();
  while (s > '9' || s < '0') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + (s ^ 48);
    s = getchar();
  }
  x *= f;
}
template <typename _T>
_T Fabs(_T x) {
  return x < 0 ? -x : x;
}
long long n, m, a[100010], b[100010];
long long f[100010][2];
long long qkpow(long long a, long long s) {
  long long res = 1;
  while (s) {
    if (s & 1) res = res * a % mo;
    a = a * a % mo;
    s >>= 1;
  }
  return res;
}
signed main() {
  read(n);
  read(m);
  for (long long i = 1; i <= n; i++) read(a[i]);
  for (long long i = 1; i <= n; i++) read(b[i]);
  f[0][0] = 1;
  long long invm = qkpow(m, mo - 2), inv2 = qkpow(2, mo - 2);
  for (long long i = 1; i <= n; i++) {
    if (a[i] > b[i] && b[i])
      f[i][1] = (f[i - 1][0] + f[i - 1][1]) % mo;
    else if (a[i] < b[i] && a[i])
      f[i][1] = f[i - 1][1];
    else if (a[i] == b[i] && a[i])
      f[i][1] = f[i - 1][1], f[i][0] = f[i - 1][0] % mo;
    else if (!a[i] && !b[i]) {
      f[i][0] = f[i - 1][0] * invm % mo;
      f[i][1] = (f[i - 1][1] +
                 f[i - 1][0] * ((1 - invm) % mo + mo) % mo * inv2 % mo) %
                mo;
    } else if (!a[i]) {
      f[i][0] = f[i - 1][0] * invm % mo;
      f[i][1] = (f[i - 1][1] +
                 f[i - 1][0] * invm % mo * ((m - b[i]) % mo + mo) % mo % mo) %
                mo;
    } else if (!b[i]) {
      f[i][0] = f[i - 1][0] * invm % mo;
      f[i][1] = (f[i - 1][1] +
                 f[i - 1][0] * invm % mo * ((a[i] - 1) % mo + mo) % mo) %
                mo;
    }
  }
  printf("%lld\n", (f[n][1] % mo + mo) % mo);
  return 0;
}
