#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int x, long long int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
bool bfs(vector<vector<int>> g, vector<int> &dist, int sv) {
  queue<int> q;
  q.push(sv);
  dist[sv] = 0;
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (auto v : g[now]) {
      if (dist[v] != -1) continue;
      dist[v] = dist[now] + 1;
      q.push(v);
    }
  }
}
int main(void) {
  long long int n, m;
  cin >> n >> m;
  vector<long long int> s(n), t(m);
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int j = 0; j < m; j++) cin >> t[j];
  vector<vector<long long int>> dp(n + 1, vector<long long int>(m + 1, 0));
  vector<vector<long long int>> sum(n + 1, vector<long long int>(m + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < n + 1; i++) sum[i][0] = 1;
  for (int j = 0; j < m + 1; j++) sum[0][j] = 1;
  for (int i = 1; i < n + 1; i++)
    for (int j = 1; j < m + 1; j++) {
      if (s[i - 1] == t[j - 1])
        dp[i][j] = sum[i - 1][j - 1];
      else
        dp[i][j] = 0;
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j];
    }
  cout << sum[n][m] % 1000000007 << endl;
}
