#include <bits/stdc++.h>
using namespace std;
template <class T>
constexpr T lcm(T m, T n) {
  return m / __gcd(m, n) * n;
}
template <typename I>
void join(ostream &ost, I s, I t, string d = " ") {
  for (auto i = s; i != t; ++i) {
    if (i != s) ost << d;
    ost << *i;
  }
  ost << endl;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &a : v) is >> a;
  return is;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
bool chmin(T &a, const U &b) {
  return (a > b ? a = b, true : false);
}
template <typename T, typename U>
bool chmax(T &a, const U &b) {
  return (a < b ? a = b, true : false);
}
template <typename T, size_t N, typename U>
void fill_array(T (&a)[N], const U &v) {
  fill((U *)a, (U *)(a + N), v);
}
const long long int mod = 1e9 + 7;
long long int dp[2200][2200];
bool visited[2200][2200];
long long int rec(int i, int j, const vector<int> &S, const vector<int> &T) {
  if (i == 0 or j == 0) return dp[i][j] = 1;
  if (visited[i][j]) return dp[i][j];
  visited[i][j] = true;
  if (S[i - 1] == T[j - 1]) {
    (dp[i][j] += rec(i - 1, j - 1, S, T)) %= mod;
  }
  (dp[i][j] +=
   rec(i - 1, j, S, T) + rec(i, j - 1, S, T) - rec(i - 1, j - 1, S, T)) %= mod;
  return dp[i][j];
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  while (cin >> N >> M) {
    vector<int> S(N), T(M);
    cin >> S >> T;
    fill_array(dp, 0);
    fill_array(visited, false);
    long long int ans = rec(N, M, S, T);
    cout << ans << endl;
  }
  return 0;
}
