#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[1001][1001];
ll n, m;
ll s[1001];
ll t[1001];
ll res = 0;
void solve() {
  for (int i = 0; i <= m; i++) dp[0][i] = 0;
  for (int i = 0; i <= n; i++) dp[i][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] + 1) % 1000000007;
      } else {
        dp[i][j] =
            (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % 1000000007;
      }
    }
  }
  res = (dp[n][m] + 1) % 1000000007;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int j = 1; j <= m; j++) cin >> t[j];
  solve();
  cout << res << endl;
  return 0;
}
