#include <bits/stdc++.h>
using namespace std;
const long long e5 = 1 << 20;
const long long mod = 1000000007;
const long long e3 = 1 << 13;
const long long INF = 1ll << 60;
long long n, m;
long long s[e3], t[e3];
long long dp[e3][e3];
long long vis[e3][e3];
long long solve(long long i, long long j) {
  if (i == n || j == m) return 0;
  if (vis[i][j]) return dp[i][j];
  vis[i][j] = 1;
  if (s[i] == t[j]) {
    dp[i][j] += 1 + solve(i + 1, j + 1);
  }
  dp[i][j] -= solve(i + 1, j + 1);
  dp[i][j] += solve(i + 1, j);
  dp[i][j] += solve(i, j + 1);
  dp[i][j] %= mod;
  return dp[i][j];
}
int main() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> s[i];
  for (long long i = 0; i < m; i++) cin >> t[i];
  cout << (solve(0, 0) + 1) % mod << endl;
}
