#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
const long long M = 100005;
long long read() {
  long long x = 0, flag = 1;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return x * flag;
}
long long n, m, p, ans, inv1, inv2, a[M], b[M];
long long qkpow(long long a, long long b) {
  long long r = 1;
  while (b > 0) {
    if (b & 1) r = r * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return r;
}
signed main() {
  n = read();
  m = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  for (long long i = 1; i <= n; i++) b[i] = read();
  p = 1;
  inv1 = qkpow(m, MOD - 2);
  inv2 = qkpow(2 * m, MOD - 2);
  for (long long i = 1; i <= n; i++) {
    if (a[i] == 0 && b[i] == 0)
      ans = (ans + p * (m - 1) % MOD * inv2 % MOD) % MOD;
    else if (a[i] == 0)
      ans = (ans + p * (m - b[i]) % MOD * inv1 % MOD) % MOD;
    else if (b[i] == 0)
      ans = (ans + p * (a[i] - 1) % MOD * inv1 % MOD) % MOD;
    else if (a[i] < b[i])
      break;
    else if (a[i] > b[i]) {
      ans = (ans + p) % MOD;
      break;
    }
    if (a[i] == 0 || b[i] == 0) p = p * inv1 % MOD;
  }
  printf("%lld\n", ans);
}
