#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
using mat = vector<vector<long long>>;
class ParseError {};
void IOS() { ios::sync_with_stdio(false), cin.tie(0); }
const long long INF = 1e16;
const long long MOD = 1e9 + 7;
const long double EPS = 1e-12;
template <typename T>
void dump(T x) {
  cout << x << endl;
}
void dumpf(long double x, int t) {
  cout << setprecision(t) << fixed << x << endl;
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  fill((T *)array, (T *)(array + N), val);
}
inline long long mod(long long a, long long b) {
  if (a > 0) return a % b;
  if (a % b == 0) return 0;
  long long x = -a / b + 1;
  a += x * b;
  return a % b;
}
long long powm(long long a, long long b, long long c) {
  if (b == 0)
    return 1;
  else if (b % 2 == 0) {
    long long d = powm(a, b / 2, c);
    return (d * d) % c;
  } else
    return (a * powm(a, b - 1, c)) % c;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long dp[2002][2002] = {};
int main() {
  IOS();
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n), t(m);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> t[j];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == t[j])
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] + 1;
      else
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j];
      dp[i + 1][j + 1] %= MOD;
    }
  }
  dump((dp[n][m] + 1) % MOD);
  return 0;
}
