#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const long long MOD = 1e9 + 7;
int S[100100];
int T[100100];
long long DP[3000][3000];
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    int s;
    cin >> s;
    S[i] = s;
  }
  for (int i = 0; i < M; i++) {
    int t;
    cin >> t;
    T[i] = t;
  }
  long long ans = 0;
  map<int, long long> ss;
  for (int i = 0; i < M + 1; i++) {
    DP[0][i] = 1;
  }
  for (int i = 0; i < N + 1; i++) {
    DP[i][0] = 1;
  }
  for (int i = 1; i <= N; i++) {
    int s = S[i - 1];
    map<int, long long> tt;
    for (int j = 1; j <= M; j++) {
      int t = T[j - 1];
      if (s == t) {
        DP[i][j] += 2 * DP[i - 1][j - 1];
      } else {
        DP[i][j] += DP[i - 1][j - 1];
      }
      DP[i][j] %= MOD;
      DP[i][j] += ss[t];
      DP[i][j] %= MOD;
      DP[i][j] += tt[s];
      DP[i][j] %= MOD;
      tt[t]++;
    }
    ss[s]++;
  }
  ans = DP[N][M] % MOD;
  cout << ans << endl;
  return 0;
}
