#include <bits/stdc++.h>
using namespace std;
const long long inff = 0x3f3f3f3f3f3f3f3f;
long long n, a[100008], b[100008], m;
long long gpow(long long a, long long b) {
  long long s = 1;
  while (b > 0) {
    if (b & 1) {
      s = (s * a) % int(1e9 + 7);
    }
    a = (a * a) % int(1e9 + 7);
    b >>= 1;
  }
  return s;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  scanf("%I64d", &n), scanf("%I64d", &m);
  for (int i(1); i <= (n); ++i) scanf("%I64d", &a[i]);
  for (int i(1); i <= (n); ++i) scanf("%I64d", &b[i]);
  long long s = 0, z = 1;
  long long qw = (m - 1) * m / 2;
  for (int i(1); i <= (n); ++i) {
    if (a[i] && b[i]) {
      if (a[i] < b[i]) break;
      if (a[i] > b[i]) {
        s += z % int(1e9 + 7);
        break;
      }
    } else if (!a[i] && !b[i]) {
      s += z * qw % int(1e9 + 7) * gpow(m, int(1e9 + 7) - 3) % int(1e9 + 7);
      s %= int(1e9 + 7);
      z = z * gpow(m, int(1e9 + 7) - 2) % int(1e9 + 7);
    } else if (!a[i] && b[i]) {
      s += z * (m - b[i]) % int(1e9 + 7) * gpow(m, int(1e9 + 7) - 2) %
           int(1e9 + 7);
      s %= int(1e9 + 7);
      z = z * gpow(m, int(1e9 + 7) - 2) % int(1e9 + 7);
    } else {
      s += z * (a[i] - 1) % int(1e9 + 7) * gpow(m, int(1e9 + 7) - 2) %
           int(1e9 + 7);
      s %= int(1e9 + 7);
      z = z * gpow(m, int(1e9 + 7) - 2) % int(1e9 + 7);
    }
  }
  cout << s % int(1e9 + 7) << endl;
  return 0;
}
