#include <bits/stdc++.h>
using namespace std;
int a[101010], b[101010];
long long power(long long x, long long y) {
  long long ret = 1;
  for (; y; y >>= 1, (x *= x) %= 1000000007)
    if (y & 1) (ret *= x) %= 1000000007;
  return ret;
}
long long inv(long long x) { return power(x, 1000000007 - 2); }
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  long long ans = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  long long tmp = 0;
  for (int i = 1; i <= m; i++)
    (tmp += (i - 1) * inv(1LL * m * m % 1000000007) % 1000000007) %= 1000000007;
  long long rem = 1;
  for (int i = 1; i <= n; i++) {
    if (!a[i] && !b[i]) {
      (ans += tmp * rem) %= 1000000007;
      (rem *= inv(m)) %= 1000000007;
    } else if (!a[i]) {
      (ans += (m - b[i]) * inv(m) % 1000000007 * rem) %= 1000000007;
      (rem *= inv(m)) %= 1000000007;
    } else if (!b[i]) {
      (ans += (a[i] - 1) * inv(m) % 1000000007 * rem) %= 1000000007;
      (rem *= inv(m)) %= 1000000007;
    } else if (a[i] > b[i]) {
      (ans += rem) %= 1000000007;
      break;
    } else if (a[i] < b[i])
      break;
  }
  printf("%I64d\n", ans);
  return 0;
}
