#include <bits/stdc++.h>
using namespace std;
long long int dp[2][100005], k, m = 1e9 + 7, n, a[100005], b[100005];
long long int p(long long int a, long long int b) {
  long long int r = 1;
  while (b) {
    if (b % 2) r = (r * a) % m;
    a = (a * a) % m;
    b /= 2;
  }
  return r;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) swap(a[i], b[i]);
  dp[0][0] = 1;
  long long int inv = p(k, m - 2);
  for (int i = 1; i <= n; i++) {
    if (a[i] > 0 && b[i] > 0) {
      if (a[i] == b[i])
        dp[0][i] += dp[0][i - 1], dp[1][i] += dp[1][i - 1];
      else if (a[i] < b[i])
        dp[1][i] += dp[0][i - 1] + dp[1][i - 1];
      else
        dp[1][i] += dp[1][i - 1];
    } else if (a[i] > 0) {
      long long int kk = k - a[i];
      kk = (kk * inv) % m;
      dp[0][i] = (inv * dp[0][i - 1]) % m;
      dp[1][i] = (dp[0][i - 1] * kk + dp[1][i - 1]) % m;
    } else if (b[i] > 0) {
      long long int kk = b[i] - 1;
      kk = (kk * inv) % m;
      dp[0][i] = (inv * dp[0][i - 1]) % m;
      dp[1][i] = (dp[0][i - 1] * kk + dp[1][i - 1]) % m;
    } else {
      dp[0][i] = (dp[0][i - 1] * inv) % m;
      long long int kk = k - 1;
      kk = (kk * inv) % m;
      kk = (kk * p(2, m - 2)) % m;
      dp[1][i] = (dp[1][i - 1] + dp[0][i - 1] * kk) % m;
    }
    dp[0][i] %= m;
    dp[1][i] %= m;
  }
  cout << dp[1][n];
  return 0;
}
