#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
const int loose = 0;
const int tight = 1;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct Edge {
  long long to, cap, rev;
  Edge(long long _to, long long _cap, long long _rev) {
    to = _to;
    cap = _cap;
    rev = _rev;
  }
};
void add_edge(vector<vector<Edge> >& G, long long from, long long to,
              long long cap, bool revFlag, long long revCap) {
  G[from].push_back(Edge(to, cap, (long long)G[to].size()));
  if (revFlag)
    G[to].push_back(Edge(from, revCap, (long long)G[from].size() - 1));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n, 0), t(m, 0);
  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));
  for (long long(i) = 0; (i) < (n + 1); (i)++) dp[i][0] = 1;
  for (long long(i) = 0; (i) < (m + 1); (i)++) dp[0][i] = 1;
  for (long long(i) = 0; (i) < (n); (i)++) {
    for (long long(j) = 0; (j) < (m); (j)++) {
      (dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) %= MOD;
      if (s[i] == t[j]) (dp[i + 1][j + 1] += dp[i][j]) %= MOD;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
