#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MAX = 100005;
const int MOD = 1000000007;
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1) s << "	";
  }
  return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}
struct UnionFind {
  vector<long long> par;
  vector<long long> sz;
  vector<long long> rank;
  UnionFind(long long n) : par(n), sz(n), rank(n) {
    for (long long i = (0); i < (n); i++) {
      par[i] = i;
      sz[i] = 1;
      rank[i] = 0;
    }
  }
  long long root(long long x) {
    if (par[x] == x) {
      return x;
    } else {
      return root(par[x]);
    }
  }
  void unite(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (rank[x] < rank[y]) {
      par[x] = y;
      sz[y] += sz[x];
    } else {
      par[y] = x;
      sz[x] += sz[y];
      if (rank[x] == rank[y]) {
        rank[x]++;
      }
    }
  }
  bool same(long long x, long long y) { return root(x) == root(y); }
  long long size(long long x) { return sz[root(x)]; }
};
long long dp[2004][2004];
long long sum[2004][2004];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n + 1);
  vector<long long> t(m + 1);
  for (long long i = (0); i < (n); i++) {
    cin >> s[i + 1];
  }
  for (long long i = (0); i < (m); i++) {
    cin >> t[i + 1];
  }
  long long ans = 0;
  dp[0][0] = 0;
  sum[0][0] = 0;
  sum[1][0] = 0;
  sum[0][1] = 0;
  cerr << "s"
       << ":" << s << endl;
  ;
  cerr << "t"
       << ":" << t << endl;
  ;
  for (long long i = (0); i < (n); i++) {
    for (long long j = (0); j < (m); j++) {
      if (s[i + 1] == t[j + 1]) {
        dp[i + 1][j + 1] = sum[i][j] + 1;
        dp[i + 1][j + 1] %= MOD;
      } else {
        dp[i + 1][j + 1] = 0;
      }
      sum[i + 1][j + 1] =
          sum[i][j + 1] + sum[i + 1][j] + dp[i + 1][j + 1] - sum[i][j];
      sum[i + 1][j + 1] %= MOD;
    }
  }
  cerr << "sum[n][m]"
       << ":" << sum[n][m] << endl;
  ;
  cout << sum[n][m] + 1 << endl;
  return 0;
}
