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