#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
template <typename T>
T gcd(T a, T b) {
  return b != 0 ? gcd(b, a % b) : a;
}
template <typename T>
struct UnionFind {
  vector<T> par;
  UnionFind(T n) : par(n, -1) {}
  void init(T n) { par.assign(n, -1); }
  T root(T x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = root(par[x]);
  }
  bool issame(T x, T y) { return root(x) == root(y); }
  bool merge(T x, T y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  int size(int x) { return -par[root(x)]; }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, M;
  cin >> N >> M;
  vector<ll> S(N), T(M);
  for (auto&& i : S) {
    cin >> i;
  }
  for (auto&& i : T) {
    cin >> i;
  }
  ll ans{};
  vector<vector<ll>> tmp(N + 1, vector<ll>(M + 1)),
      sum(N + 1, vector<ll>(M + 1));
  for (ll n{0}; n < N; n++)
    for (ll m{0}; m < M; m++) {
      if (S.at(n) == T.at(m)) {
        tmp.at(n + 1).at(m + 1) = sum.at(n).at(m) + 1;
        sum.at(n + 1).at(m + 1) = tmp.at(n + 1).at(m + 1);
        ans += tmp.at(n + 1).at(m + 1);
      }
      sum.at(n + 1).at(m + 1) +=
          (sum.at(n + 1).at(m) + sum.at(n).at(m + 1) - sum.at(n).at(m)) %
          1000000007;
    }
  cout << (ans + 1) % 1000000007 << "\n";
}
