#include <bits/stdc++.h>
using namespace std;
long long newton(long long int a, long long int b) {
  if (a == b) return a;
  while (a != 0 && b != 0) {
    if (a > b) {
      b += a;
      a = b - a;
      b -= a;
    }
    b %= a;
  }
  return a;
}
struct UnionFind {
  vector<int> p;
  UnionFind(int N) : p(N) {
    for (int i = 0; i < N; i++) {
      p[i] = i;
    }
  }
  int root(int x) {
    if (p[x] == x) return x;
    return p[x] = root(p[x]);
  }
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    p[rx] = ry;
  }
  bool issame(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};
long long div2mul_calc(long long a, long long b, long long m) {
  if (b == 0) {
    return 1;
  } else if (b % 2 == 0) {
    long long d = div2mul_calc(a, b / 2, m);
    return (d * d) % m;
  } else {
    return (a * div2mul_calc(a, b - 1, m)) % m;
  }
}
long long div2mul(long long n, long long mod) {
  return div2mul_calc(n, mod - 2, mod);
}
long long dive10(long long b, long long s, long long n, long long m) {
  b = div2mul_calc(b, n, m);
  long long i = 1;
  long long c = b;
  long long r = 1;
  long long t = b;
  long long k = 1;
  while (i) {
    if (i & s) {
      r += c * k;
      r %= m;
      k *= t;
      k %= m;
    }
    c = c + c * t;
    c %= m;
    t = t * t;
    t %= m;
    i <<= 1;
  }
  return r;
}
long long divet10(long long b, long long s, long long n, long long m) {
  b = div2mul_calc(b, n, m);
  long long i = 1;
  long long c = b;
  long long r = 1;
  long long t = b;
  long long k = 1;
  while (i) {
    if (i & s) {
      r += c * k;
      r %= m;
      k *= t;
      k %= m;
    }
    c = c + c * t;
    c %= m;
    t = t * t;
    t %= m;
    i <<= 1;
  }
  return r;
}
long long big(int n) {
  long long ret = 1;
  for (int i = 2; i <= n; ++i) {
    ret *= 2;
  }
  return ret;
}
int A[2100] = {0};
int B[2100] = {0};
int mp[2100][2100] = {0};
int main() {
  int N, M;
  cin >> N >> M;
  int i, j, k;
  for (i = 1; i <= N; ++i) {
    cin >> A[i];
  }
  for (i = 1; i <= M; ++i) {
    cin >> B[i];
  }
  mp[0][0] = 1;
  for (i = 0; i < 2010; ++i) {
    mp[i][0] = 1;
    mp[0][i] = 1;
  }
  for (i = 1; i <= N; ++i) {
    for (j = 1; j <= M; ++j) {
      mp[i][j] += mp[i][j - 1] + mp[i - 1][j];
      if (A[i] == B[j]) mp[i][j] += mp[i - 1][j - 1];
      mp[i][j] %= 1000000007;
    }
  }
  cout << mp[N][M] << endl;
  return 0;
}
