#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
const long long mod = 1e9 + 7;
const long long mod2 = 998244353;
const int oo = 0x7fffffff;
const int sup = 0x80000000;
template <typename it>
void db(it *begin, it *end) {
  while (begin != end) cout << (*begin++) << " ";
  puts("");
}
template <typename it>
string to_str(it n) {
  string s = "";
  while (n) s += n % 10 + '0', n /= 10;
  reverse(s.begin(), s.end());
  return s;
}
template <typename it>
int o(it a) {
  cout << a << endl;
  return 0;
}
long long mul(long long a, long long b, long long c) {
  long long ans = 0;
  for (; b; b >>= 1, a = (a + a) % c)
    if (b & 1) ans = (ans + a) % c;
  return ans;
}
long long ksm(long long a, long long b, long long c) {
  long long ans = 1;
  for (; b; b >>= 1, a = mul(a, a, c))
    if (b & 1) ans = mul(ans, a, c);
  return ans;
}
int n, m;
int s[N], t[N];
long long dp[2005][2005] = {0};
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
  for (int i = 1; i <= m; i++) scanf("%d", &t[i]);
  for (int i = 1; i <= n; i++) {
    for (int 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;
    }
  }
  o(dp[n][m] + 1);
}
