#include <bits/stdc++.h>
using namespace std;
template <typename T>
void debug(vector<T> v) {
  cerr << '{';
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (i) cerr << ',' << " ";
    cerr << v[i];
  }
  cerr << '}' << '\n';
}
const int md = (int)1e9 + 7;
inline int sum(int a, int b) {
  a += b;
  if (a > md) {
    a -= md;
  }
  return a;
}
inline int mul(int a, int b) { return (int)((long long)a * b % md); }
inline int power(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
inline int invert(int a) { return power(a, md - 2); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  int ans = 0;
  int p = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      if (b[i] == 0) {
        int k = mul(p, mul(invert(mul(m, m)), mul(m, mul(m - 1, invert(2)))));
        ans = sum(ans, k);
        p = mul(p, mul(1, invert(m)));
      } else {
        int k = mul(p, mul(m - b[i], invert(m)));
        ans = sum(ans, k);
        p = mul(p, mul(1, invert(m)));
      }
    } else {
      if (b[i] == 0) {
        int k = mul(p, mul(a[i] - 1, invert(m)));
        ans = sum(ans, k);
        p = mul(p, mul(1, invert(m)));
      } else {
        if (a[i] > b[i]) {
          ans = sum(ans, p);
          p = mul(p, 0);
        } else {
          if (a[i] < b[i]) {
            p = mul(p, 0);
          }
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
