#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  for (int i = 0; i < (n); i++) cin >> s[i];
  for (int i = 0; i < (m); i++) cin >> t[i];
  ll mod = 1e9 + 7;
  vector<vector<ll>> dp(n + 1, vector<ll>(m + 1)), u(n + 1, vector<ll>(m + 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] = u[i - 1][j - 1] + 1;
      u[i][j] =
          (u[i - 1][j] + u[i][j - 1] - u[i - 1][j - 1] + dp[i][j] + mod) % mod;
    }
  cout << u[n][m] << endl;
  return 0;
}
