#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
const int N = 100010;
int a[N], b[N];
int main() {
  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];
  auto mpow = [](int a, int n) {
    int r = 1;
    while (n) {
      if (n & 1) r = (r * 1ll * a) % Mod;
      a = (a * 1ll * a) % Mod;
      n >>= 1;
    }
    return r;
  };
  auto mul = [](int a, int b) { return (a * 1ll * b) % Mod; };
  auto add = [](int a, int b) { return (a + 0ll + b) % Mod; };
  int M = mpow(m, Mod - 2);
  int MM = mpow(mul(m, m), Mod - 2);
  int full = (m * 1ll * (m - 1)) / 2 % Mod;
  long long res = 0, cur = 1;
  for (int i = 0; i < n; i++) {
    if (!a[i] && !b[i]) {
      res = add(res, mul(mul(cur, full), MM));
      cur = mul(mul(cur, m), MM);
    } else if (a[i] && !b[i]) {
      res = add(res, mul(mul(cur, a[i] - 1), M));
      cur = mul(cur, M);
    } else if (!a[i] && b[i]) {
      res = add(res, mul(mul(cur, m - b[i]), M));
      cur = mul(cur, M);
    } else if (a[i] > b[i]) {
      res = add(res, cur);
      break;
    } else if (a[i] < b[i]) {
      break;
    }
  }
  cout << res << '\n';
}
