#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));
}
long long dp[2020][2020];
long long n, m;
long long s[2020];
long long t[2020];
long long dfs(long long i, long long j) {
  if (i >= n || j >= m) return 0;
  if (dp[i][j] != 0) return dp[i][j];
  long long res = 0;
  if (s[i] == t[j]) {
    (res += dfs(i + 1, j + 1) + 1) %= MOD;
  }
  (res += ((dfs(i + 1, j) + dfs(i, j + 1)) % MOD + MOD - dfs(i + 1, j + 1)) %
          MOD) %= MOD;
  dp[i][j] = res;
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m;
  for (long long(i) = 0; (i) < (n); (i)++) cin >> s[i];
  for (long long(i) = 0; (i) < (m); (i)++) cin >> t[i];
  cout << (dfs(0, 0) + 1) % MOD << endl;
  return 0;
}
