#include <bits/stdc++.h>
using namespace std;
const long long MAX5 = 1e+5 + 7;
const long long MAX7 = 1e+7 + 7;
const long long MAXN = 4 * MAX5;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const long long MOD = 1e+9 + 7;
const int N = 1e4;
long long vis[N];
vector<long long> adj[N];
long long t = 1;
long long n, m, second, cnt = 1, u, v, k;
long long dp[3000][3000], change[3000][3000];
void MAIN() {
  cin >> n >> m;
  vector<long long> a(n), b(m);
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < m; i++) cin >> b[i];
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (a[i - 1] == b[j - 1]) {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + 1;
      } else {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) - dp[i - 1][j - 1];
      }
      dp[i][j] %= MOD;
    }
  }
  cout << (dp[n][m] + 1) % MOD;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout << setprecision(12);
  ;
  mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
  ;
  while (t--) {
    MAIN();
  }
  return 0;
}
