#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B>
bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
long long inf = sizeof(long long) == sizeof(long long) ? 2e18 : 1e9 + 10;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  vector<long long> b(m);
  for (long long i = 0; i < m; i++) cin >> b[i];
  vector<vector<long long> > dp(n + 1, vector<long long>(m + 1));
  for (long long i = 0; i < n + 1; i++) dp[i][0] = 1;
  for (long long i = 0; i < m + 1; i++) dp[0][i] = 1;
  long long MOD = 1000000007;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) {
      if (a[i] == b[j]) {
        dp[i + 1][j + 1] = dp[i][j];
      }
      (dp[i + 1][j + 1] += dp[i + 1][j] + dp[i][j + 1] - dp[i][j]) %= MOD;
    }
  cout << dp[n][m] << endl;
}
