#include <bits/stdc++.h>
using namespace std;
int dy[] = {0, 0, 1, -1};
int dx[] = {
    1,
    -1,
    0,
    0,
};
vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}
long long my_pow(long long x, long long y) {
  long long rtn = 1;
  for (long long i = 0; i < y; i++) rtn *= x;
  return rtn;
}
long long get_digit_in(long long n, long long i) {
  for (long long j = 0; j < i - 1; j++) {
    n /= 10;
  }
  return n % 10;
}
long long get_digit(long long n) {
  long long rtn = 0;
  while (n > 0) {
    n /= 10;
    rtn++;
  }
  return rtn;
}
int main() {
  cout << fixed << setprecision(10);
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n);
  for (long long i = 0; i < n; i++) cin >> s[i];
  vector<long long> t(m);
  for (long long i = 0; i < m; i++) cin >> t[i];
  vector<vector<long long>> dp(n, vector<long long>(m, 0));
  vector<vector<long long>> sum(n, vector<long long>(m, 0));
  for (long long i = 0; i < n; i++) {
    if (s[i] == t[0]) dp[i][0] = 1;
  }
  for (long long j = 0; j < m; j++) {
    if (s[0] == t[j]) dp[0][j] = 1;
  }
  sum[0][0] = dp[0][0];
  for (long long i = 0; i < n - 1; i++)
    sum[i + 1][0] = sum[i][0] + dp[i + 1][0];
  for (long long j = 0; j < m - 1; j++)
    sum[0][j + 1] = sum[0][j] + dp[0][j + 1];
  for (long long i = 1; i < n; i++) {
    for (long long j = 1; j < m; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = sum[i - 1][j - 1] + 1;
      } else {
        dp[i][j] = 0;
      }
      sum[i][j] = (sum[i - 1][j] % 1000000007 + sum[i][j - 1] % 1000000007 -
                   sum[i - 1][j - 1] % 1000000007 + dp[i][j] % 1000000007) %
                  1000000007;
    }
  }
  cout << (sum[n - 1][m - 1] + 1) % 1000000007 << endl;
}
