#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T1, class T2>
ostream& operator<<(ostream& s, pair<T1, T2> P) {
  return s << '<' << P.first << ", " << P.second << '>';
}
template <class T>
ostream& operator<<(ostream& s, vector<T> P) {
  for (long long i = 0; i < P.size(); ++i) {
    if (i > 0) {
      s << " ";
    }
    s << P[i];
  }
  return s;
}
template <class T>
ostream& operator<<(ostream& s, vector<vector<T>> P) {
  for (long long i = 0; i < P.size(); ++i) {
    s << endl << P[i];
  }
  return s << endl;
}
template <class T>
ostream& operator<<(ostream& s, set<T> P) {
  for (__typeof__((P).begin()) it = (P).begin(); it != (P).end(); ++it) {
    s << "<" << *it << "> ";
  }
  return s << endl;
}
template <class T1, class T2>
ostream& operator<<(ostream& s, map<T1, T2> P) {
  for (__typeof__((P).begin()) it = (P).begin(); it != (P).end(); ++it) {
    s << "<" << it->first << "->" << it->second << "> ";
  }
  return s << endl;
}
template <class T>
void show(vector<T> v) {
  for (long long i = 0; i < v.size(); i++) {
    cerr << v[i] << " ";
  }
  cerr << "\n";
}
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n), t(m);
  long long MOD = 1e9 + 7;
  for (long long i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (long long i = 0; i < m; i++) {
    cin >> t[i];
  }
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 0));
  vector<vector<long long>> sdp(n + 1, vector<long long>(m + 1, 0));
  dp[0][0] = 1;
  for (long long i = 0; i <= n; i++) {
    for (long long j = 0; j <= m; j++) {
      if (s[i - 1] == t[j - 1] && i - 1 >= 0 && j - 1 >= 0)
        dp[i][j] += (dp[i - 1][j - 1]) % MOD;
      if (i - 1 >= 0) dp[i][j] += (dp[i - 1][j]) % MOD;
      if (j - 1 >= 0) dp[i][j] += (dp[i][j - 1]) % MOD;
      if (i - 1 >= 0 && j - 1 >= 0) dp[i][j] -= dp[i - 1][j - 1];
      dp[i][j] %= MOD;
    }
  }
  cout << dp[n][m] % MOD << endl;
  return 0;
}
