#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long MOD = 1e9 + 7;
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<long long>> dp(n + 1, vector<long long>(m + 1, 0));
  if (s[0] == t[0]) dp[1][1] = 1;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++) {
      if (i == 0 && j == 0) continue;
      if (s[i] == t[j])
        dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] + 1) % MOD;
      else
        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1] - dp[i][j]) % MOD;
    }
  cout << (dp[n][m] + 1) % MOD << endl;
}
