#include <bits/stdc++.h>
using namespace std;
const int INF = (long long int)(1LL << 30) - 1;
const double INFd = 100000000000.0;
const long long int INFl = (long long int)9223372036854775807;
const int MAX = 10000;
const long long int MOD = (long long int)1e9 + 7;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return a / gcd(a, b) * b;
}
int dx[4] = {0, -1, 0, 1}, dy[4] = {-1, 0, 1, 0};
int mdx[4] = {0, 1, 0, -1}, mdy[4] = {-1, 0, 1, 0};
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
long long int n, m;
int s[2010], t[2010];
long long int dp[2010][2010];
long long int cong[2010][2010];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) cin >> t[i];
  dp[0][0] = (s[0] == t[0]) ? 1 : 0;
  for (int i = 1; i < n; i++) {
    dp[0][i] = dp[0][i - 1] + ((t[0] == s[i]) ? 1 : 0);
  }
  for (int i = 1; i < m; i++) {
    dp[i][0] = dp[i - 1][0] + ((t[i] == s[0]) ? 1 : 0);
  }
  for (int i = 1; i < m; i++) {
    for (int j = 1; j < n; j++) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      if (t[i] == s[j]) dp[i][j] += dp[i - 1][j - 1] + 1;
      dp[i][j] %= MOD;
    }
  }
  cout << (dp[m - 1][n - 1] + 1) % MOD << endl;
  return 0;
}
