#include <bits/stdc++.h>
using namespace std;
int a[100000], b[100000];
void add(int &a, int b) { a = (a + b) % 1000000007; }
int mul(int a, int b) { return (long long)a * b % 1000000007; }
int modInverse(long long a, int m = 1000000007) {
  int ret = 1, b = m - 2;
  while (b > 0) {
    if (b & 1) ret = (ret * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  int ret = 0, probPrevSame = 1, M = modInverse(m), twoM = modInverse(2 * m);
  for (int i = 0; i < n; i++) {
    if (a[i] && b[i] && a[i] != b[i]) {
      if (a[i] > b[i]) add(ret, probPrevSame);
      break;
    }
    if (a[i] == 0 && b[i] == 0) {
      add(ret, mul(probPrevSame, mul(m - 1, twoM)));
      probPrevSame = mul(probPrevSame, M);
    } else if (a[i] == 0) {
      add(ret, mul(probPrevSame, mul(m - b[i], M)));
      probPrevSame = mul(probPrevSame, M);
    } else if (b[i] == 0) {
      add(ret, mul(probPrevSame, mul(a[i] - 1, M)));
      probPrevSame = mul(probPrevSame, M);
    }
  }
  cout << ret << "\n";
  return 0;
}
