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