#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 7;
int dp[N][N];
int a[N], b[N];
const long long int mod = 1e9 + 7;
int n, m;
long long int solve(int i, int j) {
  if (dp[i][j] != -1) {
    return dp[i][j];
  }
  if (i == n + 1 || j == m + 1) {
    return 0;
  }
  long long int ans = 0;
  if (a[i] == b[j]) {
    ans = 1 + solve(i, j + 1) + solve(i + 1, j);
  } else {
    ans = solve(i, j + 1) + solve(i + 1, j) - solve(i + 1, j + 1);
  }
  ans %= mod;
  return dp[i][j] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  cout << solve(1, 1) + 1 << "\n";
  return 0;
}
