#include <bits/stdc++.h>
using namespace std;
int n, m, x[100005], y[100005];
long long ans, cur = 1, inv;
long long po(long long b, int p) {
  long long re = 1;
  while (p) {
    if (p % 2) re = re * b % 1000000007;
    b = b * b % 1000000007;
    p /= 2;
  }
  return re;
}
int main() {
  scanf("%d%d", &n, &m);
  inv = po(m, 1000000007 - 2);
  for (int i = 0; i < n; i++) scanf("%d", x + i);
  for (int i = 0; i < n; i++) scanf("%d", y + i);
  for (int i = 0; i < n; i++) {
    if (x[i] && y[i]) {
      if (x[i] > y[i]) {
        ans = (ans + cur) % 1000000007;
        cur = 0;
      } else if (x[i] < y[i])
        cur = 0;
    } else if (x[i]) {
      ans = (ans + cur * (x[i] - 1) % 1000000007 * inv) % 1000000007;
      cur = cur * inv % 1000000007;
    } else if (y[i]) {
      ans = (ans + cur * (m - y[i]) % 1000000007 * inv) % 1000000007;
      cur = cur * inv % 1000000007;
    } else {
      ans = (ans + cur * (1000000007 + 1 - inv) % 1000000007 *
                       ((1000000007 + 1) / 2)) %
            1000000007;
      cur = cur * inv % 1000000007;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
