#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, m, s[2010], t[2010];
  long long dp[2010][2010];
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> s[i];
  for (long long i = 0; i < m; i++) cin >> t[i];
  for (long long i = 0; i < 2010; i++)
    for (long long j = 0; j < 2010; j++) dp[i][j] = 1;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = dp[i][j - 1] + dp[i - 1][j];
      } else {
        dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
      }
      dp[i][j] %= MOD;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
