#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793238460;
using namespace std;
const int N = 2005;
long long dp[N][N], vis[N][N];
long long n, m;
long long a[N], b[N];
long long go(long long i, long long j) {
  if (i >= n || j >= m) return 0;
  long long &ans = dp[i][j];
  if (vis[i][j]) return ans;
  vis[i][j] = 1;
  if (a[i] == b[j])
    ans = 1 + go(i + 1, j) + go(i, j + 1);
  else
    ans = go(i, j + 1) + go(i + 1, j) - go(i + 1, j + 1);
  if (ans >= 1000000007) ans -= 1000000007;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < m; i++) cin >> b[i];
  cout << go(0, 0) + 1;
  return 0;
}
