#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a[101000];
long long b[101000];
long long inv(long long x) {
  long long base = 1000000007 - 2;
  long long ret = 1;
  long long xt = x;
  while (base >= 1) {
    if (base & 1) ret = ret * xt % 1000000007;
    xt = xt * xt % 1000000007;
    base /= 2;
  }
  return ret;
}
signed main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  long long ans = 0;
  long long pls = 1;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long long i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (long long i = 1; i <= n; i++) {
    if (a[i] != 0 && b[i] != 0) {
      if (a[i] > b[i]) {
        ans = (ans + pls) % 1000000007;
        break;
      } else if (a[i] < b[i]) {
        break;
      }
    } else if (a[i] == 0 && b[i] == 0) {
      ans = (ans + ((m) * (m - 1) / 2) % 1000000007 * inv(m * m % 1000000007) %
                       1000000007 * pls) %
            1000000007;
      pls = pls * inv(m) % 1000000007;
    } else if (a[i] == 0) {
      pls = pls * inv(m) % 1000000007;
      ans = (ans + (m - b[i]) * pls) % 1000000007;
    } else if (b[i] == 0) {
      pls = pls * inv(m) % 1000000007;
      ans = (ans + (a[i] - 1) * pls) % 1000000007;
    }
  }
  cout << ans << endl;
}
