#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int absl(long long int a) { return a >= 0 ? a : -a; }
long long int maxl(long long int a, long long int b) { return a >= b ? a : b; }
long long int exp(long long int a, long long int n) {
  if (n == 0) return 1;
  if (n == 1) return a;
  if (n & 1)
    return (a % mod * exp((a * a) % mod, n / 2) % mod) % mod;
  else
    return exp((a * a) % mod, n / 2) % mod;
}
double mi(double a, double b) { return a < b ? a : b; }
double mx(double a, double b) { return a >= b ? a : b; }
struct type {
  int l, r;
};
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n + 1), t(m + 1);
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= m; i++) cin >> t[i];
  vector<vector<long long int> > v(n + 1, vector<long long int>(m + 1, 1));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      v[i][j] = (v[i - 1][j] % mod + v[i][j - 1] % mod) % mod;
      if (s[i] != t[j]) v[i][j] -= v[i - 1][j - 1];
    }
  cout << v[n][m] << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  { solve(); }
  return 0;
}
