#include <bits/stdc++.h>
using namespace std;
const long long N = 2e3 + 5;
const long long MAX = 1e2 + 5;
long long arr[N];
long long brr[N];
const long long mod = 1e9 + 7;
long long DP[N][N];
long long f(long long i, long long j, long long n, long long m) {
  if (i == n or j == m) return 1;
  if (DP[i][j] != -1) return DP[i][j];
  if (arr[i] == brr[j]) {
    long long ret = f(i + 1, j + 1, n, m);
    ret %= mod;
    return DP[i][j] = f(i + 1, j, n, m) + f(i, j + 1, n, m);
  }
  long long ans1 = f(i + 1, j, n, m);
  long long ans2 = f(i, j + 1, n, m);
  long long ret = ans1 + ans2;
  ret %= mod;
  ret = ret - f(i + 1, j + 1, n, m);
  ret += mod;
  ret %= mod;
  return DP[i][j] = ret;
}
int32_t main() {
  long long n, m;
  cin >> n >> m;
  memset(DP, -1, sizeof(DP));
  for (long long i = 0; i < n; i++) cin >> arr[i];
  for (long long i = 0; i < m; i++) cin >> brr[i];
  cout << f(0, 0, n, m);
}
