#include <bits/stdc++.h>
using namespace std;
bool Finish_read;
template <class T>
inline void read(T &x) {
  Finish_read = 0;
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    if (ch == EOF) return;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  x *= f;
  Finish_read = 1;
}
template <class T>
inline void print(T x) {
  if (x / 10 != 0) print(x / 10);
  putchar(x % 10 + '0');
}
template <class T>
inline void writeln(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
  putchar('\n');
}
template <class T>
inline void write(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long ksm(long long a, long long b, long long mod) {
  long long ans = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
  }
  return ans;
}
long long phi(long long n) {
  long long rea = n;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      rea = rea - rea / i;
      while (n % i == 0) n /= i;
    }
  }
  if (n > 1) rea = rea - rea / n;
  return rea;
}
void exgcd(int a, int b, int &x, int &y, int &d) {
  if (!b) {
    x = 1;
    y = 0;
    d = a;
  } else
    exgcd(b, a % b, y, x, d), y -= a / b * x;
}
inline int inv(int a, int mod) {
  int x, y, d;
  exgcd(a, mod, x, y, d);
  x = (x % mod + mod) % mod;
  return x;
}
const int INF = 0x3f3f3f3f;
const int maxn = 1000 + 5;
const int mod = 1000000007;
int n, m;
long long dp[maxn][maxn];
int a[maxn], b[maxn];
int main() {
  while (~scanf("%d%d", &n, &m)) {
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (a[i] == b[j])
          dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + 1;
        else
          dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
        dp[i][j] = (dp[i][j] + mod) % mod;
      }
    }
    printf("%lld\n", (dp[n][m] + 1) % mod);
  }
  return 0;
}
