#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, m;
  cin >> n >> m;
  std::vector<int> s(n);
  vector<int> t(m);
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    cin >> s[i];
  for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m));
       i += 1 - 2 * ((0) > (m)))
    cin >> t[i];
  vector<vector<int> > dp(n + 1, vector<int>(m + 1, 0));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i - 1] == t[j - 1])
        dp[i][j] = (1 + (dp[i][j - 1] + dp[i - 1][j]) % mod) % mod;
      else
        dp[i][j] =
            (dp[i][j - 1] + (dp[i - 1][j] - dp[i - 1][j - 1]) % mod) % mod;
    }
  }
  long long int ans = (dp[n][m] + 1) % mod;
  cout << ans;
  return 0;
}
