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