#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 1;
const long long mod = 1e9 + 7;
long long n, m, s1[maxn], s2[maxn], c;
long long bin_pow(long long a, long long n1) {
  if (n1 == 0) return 1;
  if (n1 & 1)
    return ((bin_pow(a, n1 - 1) % mod) * a) % mod;
  else {
    long long b = bin_pow(a, n1 / 2) % mod;
    return (b * b) % mod;
  }
}
long long calc(long long ind) {
  if (ind > n) return 0;
  if (s1[ind] > s2[ind] && s1[ind] != 0 && s2[ind] != 0) return 1;
  if (s1[ind] < s2[ind] && s1[ind] != 0 && s2[ind] != 0) return 0;
  if (s1[ind] != 0 && s2[ind] != 0 && s2[ind] == s1[ind])
    return (calc(ind + 1) % mod);
  if (s1[ind] == 0 && s2[ind] != 0)
    return (((calc(ind + 1) * c) % mod) + (((m - s2[ind]) * c) % mod)) % mod;
  if (s1[ind] != 0 && s2[ind] == 0)
    return (((calc(ind + 1) * c) % mod) + (((s1[ind] - 1) * c) % mod)) % mod;
  if (s1[ind] == 0 && s2[ind] == 0)
    return (((calc(ind + 1) * c) % mod) +
            (((m - 1) * bin_pow(2 * m, mod - 2)) % mod)) %
           mod;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> s1[i];
  }
  for (int j = 1; j <= n; ++j) {
    cin >> s2[j];
  }
  c = bin_pow(m, mod - 2);
  cout << calc(1);
  return 0;
}
