#include <bits/stdc++.h>
using namespace std;
static const int MAX = 1e6;
static const int NIL = -1;
static const long long INF = 1 << 21;
static const long long MOD = 1e9 + 7;
bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
  return arg1.first > arg2.first;
}
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> S(N);
  vector<int> T(M);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  for (int j = 0; j < M; j++) {
    cin >> T.at(j);
  }
  long long dp[N + 5][M + 5];
  for (int i = 0; i < N + 5; i++) {
    for (int j = 0; j < M + 5; j++) {
      if (i == 0 || j == 0)
        dp[i][j] = 1;
      else
        dp[i][j] = 0;
    }
  }
  long long ans = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (S.at(i - 1) == T.at(j - 1)) {
        for (int k = 1; k <= i - 1; k++) {
          for (int l = 1; l <= j - 1; l++) {
            dp[i][j] += dp[k][l] % MOD;
          }
        }
        dp[i][j] += 1;
        ans += dp[i][j];
        ans %= MOD;
      } else
        dp[i][j] = 0;
    }
  }
  cout << ans << endl;
  return (0);
}
