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