#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
inline long long getint() {
  long long _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
  if (_tc == '-') _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
inline long long add(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline long long sub(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline long long mul(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
long long mypow(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 1LL;
  long long _ret = mypow(mul(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = mul(_ret, _a, _mod);
  return _ret;
}
long long mymul(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 0LL;
  long long _ret = mymul(add(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = add(_ret, _a, _mod);
  return _ret;
}
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
void sleep(double sec = 1021) {
  clock_t s = clock();
  while (clock() - s < CLOCKS_PER_SEC * sec)
    ;
}
int __ = 1, _cs;
int inv[101010];
void build() {
  inv[0] = 1;
  for (int i = 1; i < 101010; i++)
    inv[i] = mypow(i, 1000000007LL - 2, 1000000007LL);
}
int n, m, a[2][101010];
void init() {
  n = getint();
  m = getint();
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < n; j++) a[i][j] = getint();
  }
}
int inv2 = (1000000007LL + 1) / 2;
void solve() {
  int ans = 0, same = 1;
  for (int i = 0; i < n; i++) {
    if (a[0][i] and a[1][i]) {
      if (a[0][i] < a[1][i]) break;
      if (a[0][i] > a[1][i]) {
        ans = add(ans, same);
        break;
      }
      continue;
    }
    if (a[0][i]) {
      int smaller = mul(a[0][i] - 1, inv[m]);
      ans = add(ans, mul(smaller, same));
      same = mul(same, inv[m]);
      continue;
    }
    if (a[1][i]) {
      int larger = mul(m - a[1][i], inv[m]);
      ans = add(ans, mul(larger, same));
      same = mul(same, inv[m]);
      continue;
    }
    ans =
        add(ans, mul(same, mul(mul(mul(m - 1, m), inv2), mul(inv[m], inv[m]))));
    same = mul(same, inv[m]);
  }
  cout << ans << endl;
}
int main() {
  build();
  while (__--) {
    init();
    solve();
  }
}
