#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, inf = 1e9 + 7;
long long n, k, i, j;
long long A[N], B[N];
inline long long expo(long long n, long long k, long long p = inf) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
inline long long inv(long long a) { return expo(a, inf - 2); }
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long i, j, a, b, cur = 1, ans = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) cin >> A[i];
  for (i = 0; i < n; i++) cin >> B[i];
  for (i = 0; i < n; i++) {
    if (!A[i] || !B[i]) {
      if (!A[i] && !B[i])
        ans += cur * (k - 1) % inf * inv(k * 2) % inf;
      else if (!A[i])
        ans += cur * (k - B[i]) % inf * inv(k) % inf;
      else if (!B[i])
        ans += cur * (A[i] - 1) % inf * inv(k) % inf;
      cur = cur * inv(k) % inf;
    } else {
      if (A[i] > B[i]) {
        ans += cur;
        return cout << ans % inf, 0;
      } else if (A[i] < B[i])
        return cout << ans % inf, 0;
    }
  }
  cout << ans % inf;
}
