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