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