#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> S(N), T(M);
  for (int i = (int)(0); i < (int)(N); i++) cin >> S[i];
  for (int i = (int)(0); i < (int)(M); i++) cin >> T[i];
  vector<vector<long long> > sum(N + 1, vector<long long>(M + 1));
  vector<vector<long long> > dp(N + 1, vector<long long>(M + 1));
  for (int i = (int)(0); i < (int)(N); i++) {
    for (int j = (int)(0); j < (int)(M); j++) {
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] = sum[i][j] + 1;
        dp[i + 1][j + 1] %= mod;
      }
      sum[i + 1][j + 1] =
          sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + dp[i + 1][j + 1];
      sum[i + 1][j + 1] %= mod;
    }
  }
  int cnt = 1;
  for (int i = (int)(0); i < (int)(N + 1); i++) {
    for (int j = (int)(0); j < (int)(M + 1); j++) {
      cnt += dp[i][j];
      cnt %= mod;
    }
  }
  cout << cnt << endl;
  return 0;
}
