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