#include <bits/stdc++.h>
using namespace std;
int main() {
  long long dp[2005][2005] = {0}, sum[2005][2005] = {0}, mod = 1000000007;
  int n, m, s[2005], t[2005], i, j, k;
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> s[i];
  for (i = 1; i <= m; i++) cin >> t[i];
  for (i = 1; i <= n; i++) {
    for (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;
      if (i == 1)
        sum[i][j] = (sum[i][j - 1] + dp[i][j]) % mod;
      else if (j == 1)
        sum[i][j] = (sum[i - 1][j] + dp[i][j]) % mod;
      else
        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 << endl;
  return 0;
}
