#include <bits/stdc++.h>
using namespace std;
clock_t time_p = clock();
void ktj() {
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
const int mod = 1e9 + 7;
const int N = 2000 + 5;
int dp[N][N], a[N], b[N];
int n, m;
int solve(int i, int j) {
  if (i >= n or j >= m) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  int ans = 0;
  if (a[i] == b[j])
    ans = (1 + solve(i + 1, j) % mod + solve(i, j + 1) % mod);
  else
    ans = (solve(i + 1, j) % mod + solve(i, j + 1) % mod -
           solve(i + 1, j + 1) % mod + mod) %
          mod;
  return (dp[i][j] = ans);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  memset(dp, -1, sizeof dp);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  int ans = 1;
  ans = (ans % mod + solve(0, 0) % mod) % mod;
  cout << ans << '\n';
  ktj();
}
