#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 10000;
const long long INFLL = 4e18;
const int dr[] = {-1, 0, 1, 0, -1, 1, 1, -1};
const int dc[] = {0, 1, 0, -1, 1, 1, -1, -1};
int n, m;
long long a[100005];
long long b[100005];
long long denom;
long long powMod(long long x, long long k) {
  if (k == 0) return 1LL;
  if (k == 1) return x;
  long long ret = powMod(x, k / 2);
  ret = (ret * ret) % MOD;
  if (k & 1) ret = (ret * x) % MOD;
  return ret;
}
long long solve(int i) {
  if (i == n) return 0LL;
  if (a[i] == 0 && b[i] > 0) {
    long long p = m - b[i];
    return (((p * denom) % MOD) + ((denom * solve(i + 1)) % MOD)) % MOD;
  } else if (a[i] > 0 && b[i] == 0) {
    long long p = a[i] - 1;
    return (((p * denom) % MOD) + ((denom * solve(i + 1)) % MOD)) % MOD;
  } else if (a[i] == 0 && b[i] == 0) {
    return ((((m - 1) * powMod(2 * m, MOD - 2)) % MOD) +
            ((denom * solve(i + 1)) % MOD)) %
           MOD;
  } else if (a[i] > 0 && b[i] > 0) {
    if (a[i] > b[i])
      return 1LL;
    else if (a[i] < b[i])
      return 0LL;
    else
      return solve(i + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.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];
  }
  denom = powMod(m, MOD - 2);
  long long ans = solve(0);
  printf("%lld\n", ans);
  return 0;
}
