#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long INF = 1e18;
void chmin(long long &a, long long b) {
  if (a > b) a = b;
}
void chmax(long long &a, long long b) {
  if (a < b) a = b;
}
void pmod(long long &a, long long b) { a = (a + b) % MOD; }
void qmod(long long &a, long long b) { a = (a * b) % MOD; }
void ans1(bool x) {
  if (x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
void ans2(bool x) {
  if (x)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
void ans3(bool x) {
  if (x)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;
}
void ans(bool x, long long y, long long z) {
  if (x)
    cout << y << endl;
  else
    cout << z << endl;
}
void ans(bool x, string y, string z) {
  if (x)
    cout << y << endl;
  else
    cout << z << endl;
}
long long gcd(long long x, long long y) {
  long long r;
  while ((r = x % y) != 0) {
    x = y;
    y = r;
  }
  return y;
}
int main() {
  long long i, j, o;
  long long res = 0, res1 = INF, res2 = -INF, buf = 0, buf1 = 0, buf2 = 0,
            buf3 = 0, buf4 = 0, sum = 0;
  long long l, r;
  bool judge = true;
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n), t(m);
  for (i = 0; i < n; i++) cin >> s[i];
  for (i = 0; i < m; i++) cin >> t[i];
  long long dp[n][m];
  if (s[0] == t[0])
    dp[0][0] = 1;
  else
    dp[0][0] = 0;
  for (i = 1; i < n; i++) {
    if (s[i] == t[0])
      dp[i][0] = (dp[i - 1][0] + 1) % MOD;
    else
      dp[i][0] = dp[i - 1][0];
  }
  for (i = 1; i < m; i++) {
    if (s[0] == t[i])
      dp[0][i] = (dp[0][i - 1] + 1) % MOD;
    else
      dp[0][i] = dp[0][i - 1];
  }
  for (i = 1; i < n; i++) {
    for (j = 1; j < m; j++) {
      if (s[i] == t[j])
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] + 1) % MOD;
      else
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % MOD;
    }
  }
  cout << dp[n - 1][m - 1] + 1 << endl;
  return 0;
}
