#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  const long long mod = 1e9 + 7;
  int 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));
  for (long long i = 0; i < (n + 1); i++) {
    for (long long j = 0; j < (m + 1); j++) {
      if (i == 0 || j == 0)
        dp[i][j] = 1;
      else {
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % mod;
        if (s[i - 1] != s[j - 1])
          dp[i][j] = (dp[i][j] + mod - dp[i - 1][j - 1]) % mod;
      }
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
