#include <bits/stdc++.h>
#pragma warning(disable : 4786)
#pragma warning(disable : 4996)
using namespace std;
const long long int MOD = 1000000007;
int n, m, A[100005], B[100005];
long long int prob[100005];
long long int bigmod(long long int a, long long int b) {
  if (b == 0) return 1;
  long long int x = bigmod(a, b / 2);
  x = (x * x) % MOD;
  if (b & 1) x = (x * a) % MOD;
  return x;
}
int main() {
  while (scanf("%d %d", &n, &m) != EOF) {
    for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
    for (int i = 1; i <= n; i++) scanf("%d", &B[i]);
    prob[n + 1] = 0;
    long long int invm = bigmod(m, MOD - 2);
    long long int inv2 = bigmod(2, MOD - 2);
    for (int i = n; i >= 1; i--) {
      if (!A[i] && !B[i]) {
        prob[i] = ((((m * (m - 1LL)) % MOD) * invm) % MOD) * invm;
        prob[i] %= MOD;
        prob[i] *= inv2;
        prob[i] %= MOD;
        prob[i] += invm * prob[i + 1];
      } else if (!A[i]) {
        prob[i] = invm * prob[i + 1];
        prob[i] += (m - B[i]) * invm;
      } else if (!B[i]) {
        prob[i] = invm * prob[i + 1];
        prob[i] += (A[i] - 1) * invm;
      } else {
        if (A[i] == B[i])
          prob[i] = prob[i + 1];
        else
          prob[i] = A[i] > B[i];
      }
      prob[i] %= MOD;
    }
    printf("%lld\n", prob[1]);
  }
  return 0;
}
