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