#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 T>
void YesNo(T a) {
  cout << (a ? "Yes" : "No") << "\n";
}
template <class T>
void YESNO(T a) {
  cout << (a ? "YES" : "NO") << "\n";
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void uniq(vector<long long>& vec) {
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
}
void start() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
}
signed main() {
  start();
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n), t(m);
  for (long long i = 0; i < n; ++i) cin >> s[i];
  for (long long i = 0; i < m; ++i) cin >> t[i];
  const long long h = 2010, w = 2010;
  vector<vector<long long> > dp(h, vector<long long>(w, 0)),
      sum(h, vector<long long>(w, 0));
  for (long long i = 1; i < n + 1; ++i) {
    for (long long j = 1; j < m + 1; ++j) {
      if (s[i - 1] == t[j - 1]) dp[i][j] = (sum[i - 1][j - 1] + 1) % 1000000007;
      sum[i][j] =
          (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j]) %
          1000000007;
    }
  }
  cout << (sum[n][m] + 1) % 1000000007 << "\n";
  return 0;
}
