#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  int c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}
struct UnionFind {
  vector<int> par;
  UnionFind(int N) : par(N) {
    for (int i = 0; i < N; i++) par[i] = i;
  }
  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
  }
  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};
long long M = 1000000007;
vector<long long> fac(300001);
vector<long long> ifac(300001);
long long mpow(long long x, long long n) {
  long long ans = 1;
  while (n != 0) {
    if (n & 1) ans = ans * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return ans;
}
long long comb(long long a, long long b) {
  if (a == 0 && b == 0) return 1;
  if (a < b || a < 0) return 0;
  long long tmp = ifac[a - b] * ifac[b] % M;
  return tmp * fac[a] % M;
}
long long modinv(long long a) {
  long long b = M, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= M;
  if (u < 0) u += M;
  return u;
}
vector<vector<long long>> mul(vector<vector<long long>> a,
                              vector<vector<long long>> b, int n) {
  int i, j, k, t;
  vector<vector<long long>> c(n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      t = 0;
      for (k = 0; k < n; k++) t = (t + a[i][k] * b[k][j] % M) % M;
      c[i].push_back(t);
    }
  }
  return c;
}
int main() {
  long long n, m, s[2222], t[2222], dp[2222][2222], i, j;
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> s[i];
  for (i = 1; i <= m; i++) cin >> t[i];
  for (i = 0; i <= n; i++) dp[i][0] = 1;
  for (j = 0; j <= m; j++) dp[0][j] = 1;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      if (s[i] == t[j]) dp[i][j] += dp[i - 1][j - 1];
      dp[i][j] %= M;
    }
  }
  cout << dp[n][m] << endl;
}
