#include <bits/stdc++.h>
using namespace std;
template <typename first, typename second>
ostream &operator<<(ostream &os, const pair<first, second> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  typename vector<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  os << "[";
  typename set<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename first, typename second>
ostream &operator<<(ostream &os, const map<first, second> &v) {
  os << "[";
  typename map<first, second>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << it->first << " = " << it->second;
  }
  return os << "]";
}
long long n, m;
vector<long long> a, b;
long long dp[3000][3000];
long long fun(long long N, long long M) {
  if (dp[N][M] != -1) {
    return dp[N][M];
  }
  if (N == 0 || M == 0) {
    return dp[N][M] = 0;
  } else {
    long long ans = 0;
    if (a[N - 1] == b[M - 1]) {
      ans++;
      for (long long i = 0; i < (N - 1); i++) {
        for (long long j = 0; j < (M - 1); j++) {
          ans = (ans + fun(i + 1, j + 1)) % 1000000007;
        }
      }
    }
    return dp[N][M] = ans;
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  memset(dp, -1, sizeof(dp));
  a.resize(n);
  b.resize(m);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < m; i++) {
    cin >> b[i];
  }
  long long ans = 1;
  for (long long i = n - 1; i >= 0; i--) {
    for (long long j = m - 1; j >= 0; j--) {
      ans = (ans + fun(i + 1, j + 1)) % 1000000007;
    }
  }
  cout << ans << "\n";
  return 0;
}
