#include <bits/stdc++.h>
using namespace std;
const int size = 1e5 + 10;
int a[size], b[size], n;
const int mod = 1e9 + 7;
long long dp[size], m;
long long fast_expo(long long b, long long e) {
  long long ans = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ans = (b * ans) % mod;
    b = (b * b) % mod;
  }
  return ans;
}
long long prob(long long a, long long b) {
  return (a * fast_expo(b, mod - 2)) % mod;
}
long long solve(int i) {
  if (dp[i] != -1) return dp[i];
  if (i >= n) return 0;
  if (a[i] == b[i] && a[i] != 0)
    dp[i] = solve(i + 1);
  else if (a[i] > b[i] && a[i] != 0 && b[i] != 0)
    dp[i] = 1;
  else if (a[i] < b[i] && a[i] != 0 && b[i] != 0)
    dp[i] = 0;
  else if (a[i] == 0 && b[i] != 0) {
    dp[i] = (prob(m - b[i], m) + (prob(1, m) * solve(i + 1)) % mod) % mod;
  } else if (b[i] == 0 && a[i] != 0) {
    dp[i] = (prob(a[i] - 1, m) + (prob(1, m) * solve(i + 1)) % mod) % mod;
  } else {
    dp[i] = (prob((m - 1), 2 * m) + (prob(1, m) * solve(i + 1)) % mod) % mod;
  }
  dp[i] %= mod;
  return dp[i];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  memset(dp, -1, sizeof dp);
  cout << solve(0);
  return 0;
}
