#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 = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = (sum[i - 1][j - 1] + 1) % mod;
      } else {
        dp[i][j] = 0;
      }
      sum[i][j] =
          (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j]) % mod;
    }
  }
  cout << (sum[n][m] + 1) % mod << endl;
  return 0;
}
