#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000;
int n, m;
long long int mod = 1e9 + 7;
long long int dp[maxn + 1][maxn + 1] = {0};
long long int sum[maxn + 1][maxn + 1] = {0};
long long int s[maxn + 1], t[maxn + 1];
int main() {
  cin >> n >> m;
  for (long long int i = 0; i < n; i++) cin >> s[i + 1];
  for (long long int i = 0; i < m; i++) cin >> t[i + 1];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      dp[i][j] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = 0;
      if (s[i] == t[j]) dp[i][j] += dp[i - 1][j - 1];
      dp[i][j] += dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
      dp[i][j] = dp[i][j] % mod;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
