#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int MAX = 1e5;
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
long long a[MAX + 5];
long long b[MAX + 5];
long long modpow(long long base, long long e, long long mod) {
  long long res = 1;
  while (e) {
    if (e & 1) res = (res * base) % mod;
    base = (base * base) % mod;
    e /= 2;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  long long n, i, j;
  long long m;
  int flag = 0, f2 = 0;
  cin >> n >> m;
  long long q = 1;
  for ((i) = 0; (i) < (n); ++(i)) cin >> a[i];
  for ((i) = 0; (i) < (n); ++(i)) cin >> b[i];
  long long ans = 0, multiplier = 1;
  for ((i) = 0; (i) < (n); ++(i)) {
    if (a[i] == 0 && b[i] == 0) {
      long long p = (m - 1) * modpow((2 * m) % MOD, MOD - 2, MOD);
      p %= MOD;
      p *= multiplier;
      p %= MOD;
      ans += p;
      ans %= MOD;
      multiplier *= modpow(m, MOD - 2, MOD);
      multiplier %= MOD;
    } else if (a[i] == 0) {
      long long p = (m - b[i]) * modpow(m, MOD - 2, MOD);
      p %= MOD;
      p *= multiplier;
      p %= MOD;
      ans += p;
      ans %= MOD;
      multiplier *= modpow(m, MOD - 2, MOD);
      multiplier %= MOD;
    } else if (b[i] == 0) {
      long long p = (a[i] - 1) * modpow(m, MOD - 2, MOD);
      p %= MOD;
      p *= multiplier;
      p %= MOD;
      ans += p;
      ans %= MOD;
      multiplier *= modpow(m, MOD - 2, MOD);
      multiplier %= MOD;
    } else if (a[i] == b[i]) {
    } else {
      if (a[i] > b[i]) ans = (ans + multiplier) % MOD;
      break;
    }
  }
  cout << ans;
}
