#include <bits/stdc++.h>
using namespace std;
template <typename T>
using v = vector<T>;
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K>
using ump = unordered_map<T, K>;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const long long mod = 1000000007;
const long long inf = long long(1e9);
const long long e5 = long long(1e5);
const long long ll_inf = long long(1e9) * long long(1e9);
long long inl() {
  long long x;
  cin >> x;
  return (x);
}
string ins() {
  string x;
  cin >> x;
  return (x);
}
long long count_common_sub_sequence(vector<long long> &s1,
                                    vector<long long> &s2) {
  long long n1, n2;
  n1 = s1.size();
  n2 = s2.size();
  long long arr[n1 + 1][n2 + 1];
  for (int i = 0; i <= n1; i++) {
    for (int j = 0; j <= n2; j++) {
      arr[i][j] = 0;
    }
  }
  for (int i = 1; i <= n1; i++) {
    for (int j = 1; j <= n2; j++) {
      if (s1[i - 1] == s2[j - 1]) {
        arr[i][j] = 1 + ((arr[i][j - 1] + arr[i - 1][j]) % mod);
        arr[i][j] %= mod;
      } else {
        arr[i][j] =
            (arr[i][j - 1] + arr[i - 1][j]) % mod - (arr[i - 1][j - 1] % mod);
        arr[i][j] %= mod;
      }
    }
  }
  return arr[n1][n2];
}
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n), t(m);
  for (long long i = 0; i < (long long)(n); i++) cin >> s[i];
  for (long long i = 0; i < (long long)(m); i++) cin >> t[i];
  cout << (1 + count_common_sub_sequence(s, t)) % mod << endl;
  return 0;
}
