#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, t = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') t = -1, ch = getchar();
  while (ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
  return x * t;
}
long long fpow(long long a, long long b) {
  long long s = 1;
  while (b) {
    if (b & 1) s = 1ll * s * a % 1000000007;
    a = 1ll * a * a % 1000000007;
    b >>= 1;
  }
  return s;
}
int n, m;
int s1[120000], s2[120000];
long long ans = 0, p = 1;
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; ++i) s1[i] = read();
  for (int i = 1; i <= n; ++i) s2[i] = read();
  long long inv = fpow(m, 1000000007 - 2);
  for (int i = 1; i <= n; ++i) {
    if (!s1[i] && !s2[i]) {
      long long ss = (1ll * m * (m - 1) / 2) % 1000000007;
      long long pp = 1ll * p * ss % 1000000007;
      pp = 1ll * pp * inv % 1000000007 * inv % 1000000007;
      ans = (ans + pp) % 1000000007;
      p = 1ll * p * inv % 1000000007;
    } else if (!s1[i] && s2[i]) {
      long long pp = 1ll * p * (m - s2[i]) % 1000000007;
      pp = 1ll * pp * inv % 1000000007;
      ans = (ans + pp) % 1000000007;
      p = 1ll * p * inv % 1000000007;
    } else if (s1[i] && !s2[i]) {
      long long pp = 1ll * p * (s1[i] - 1) % 1000000007;
      pp = 1ll * pp * inv % 1000000007;
      ans = (ans + pp) % 1000000007;
      p = 1ll * p * inv % 1000000007;
    } else {
      if (s2[i] > s1[i]) break;
      if (s1[i] > s2[i]) {
        ans = (ans + p) % 1000000007;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
