#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
const int MAX = 1e5;
const int Mod = 1e9 + 7;
long long power[MAXN * MAXN];
int eq[MAXN][MAXN];
int cnt[MAXN][MAXN];
int N, M;
int S[MAXN], T[MAXN];
void init() {
  power[0] = 1;
  for (int i = 1; i <= N * M; ++i) power[i] = power[i - 1] * 2 % Mod;
  for (int i = 0; i < (N); ++i) {
    for (int j = 0; j < (M); ++j) {
      if (S[i] == T[j]) eq[i][j] = 1;
    }
  }
  for (int i = N - 1; i >= 0; --i) {
    for (int j = M - 1; j >= 0; --j) {
      cnt[i][j] = eq[i][j] + cnt[i + 1][j] + cnt[i][j + 1] - cnt[i + 1][j + 1];
    }
  }
}
void solve() {
  init();
  long long ans = 1;
  for (int i = 0; i < (N); ++i) {
    for (int j = 0; j < (M); ++j) {
      if (eq[i][j]) {
        ans += power[cnt[i + 1][j + 1]];
        ans %= Mod;
      }
    }
  }
  cout << ans % Mod << endl;
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < (N); ++i) cin >> S[i];
  for (int i = 0; i < (M); ++i) cin >> T[i];
  solve();
  return 0;
}
