#include <bits/stdc++.h>
using namespace std;
template <class T>
void cout_vec(const vector<T> &vec) {
  for (auto itr : vec) cout << itr << ' ';
  cout << '\n';
}
const long long mod = 1e9 + 7;
long long dp[3000][3000];
long long sum[3000][3000];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n + 1), t(m + 1);
  for (long long i = 1; i < n + 1; i++) cin >> s[i];
  for (long long i = 1; i < m + 1; i++) cin >> t[i];
  dp[0][0] = 1;
  for (long long i = 0; i < n + 1; i++) sum[i][0] = 1;
  for (long long j = 0; j < m + 1; j++) sum[0][j] = 1;
  long long ans = 1;
  for (long long i = 1; i < n + 1; i++)
    for (long long j = 1; j < m + 1; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = sum[i - 1][j - 1];
        sum[i][j] =
            sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j];
        sum[i][j] %= mod;
        ans += dp[i][j];
        ans %= mod;
      } else {
        sum[i][j] =
            sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j];
        sum[i][j] %= mod;
      }
    }
  cout << ans << endl;
}
