#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
struct ModInt {
  long long val;
  ModInt() : val(0ll) {}
  ModInt(long long v)
      : val(((v % 1000000007ll) + 1000000007ll) % 1000000007ll) {}
  ModInt exp(long long y) const {
    if (!y) return ModInt(1ll);
    ModInt a = exp(y / 2ll);
    a *= a;
    if (y & 1) a *= (*this);
    return a;
  }
  bool operator==(const ModInt& x) const { return val == x.val; }
  inline bool operator!=(const ModInt& x) const { return !(*this == x); }
  bool operator<(const ModInt& x) const { return val < x.val; }
  bool operator>(const ModInt& x) const { return val > x.val; }
  inline bool operator>=(const ModInt& x) const { return !(*this < x); }
  inline bool operator<=(const ModInt& x) const { return !(*this > x); }
  ModInt& operator+=(const ModInt& x) {
    if ((val += x.val) >= 1000000007ll) val -= 1000000007ll;
    return *this;
  }
  ModInt& operator-=(const ModInt& x) {
    if ((val += 1000000007ll - x.val) >= 1000000007ll) val -= 1000000007ll;
    return *this;
  }
  ModInt& operator*=(const ModInt& x) {
    (val *= x.val) %= 1000000007ll;
    return *this;
  }
  ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
  ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
  ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
};
istream& operator>>(istream& i, ModInt& x) {
  i >> x.val;
  return i;
}
ostream& operator<<(ostream& o, const ModInt& x) {
  o << x.val;
  return o;
}
ModInt pow(ModInt a, long long x) {
  ModInt res = ModInt(1ll);
  while (x) {
    if (x & 1) res *= a;
    x >>= 1;
    a = a * a;
  }
  return res;
}
const int SIZE = 100100;
ModInt inv[SIZE + 10], fac[SIZE + 10], facinv[SIZE + 10];
ModInt nCr(int n, int r) {
  assert(!(n < r));
  assert(!(n < 0 || r < 0));
  return fac[n] * facinv[r] * facinv[n - r];
}
void init() {
  fac[0] = ModInt(1ll);
  for (int i = 1; i <= SIZE; i++) fac[i] = fac[i - 1] * ModInt(i);
  inv[1] = ModInt(1ll);
  for (int i = 2; i <= SIZE; i++)
    inv[i] = ModInt(0ll) - ModInt(1000000007ll / i) * inv[1000000007ll % i];
  facinv[0] = ModInt(1ll);
  for (int i = 1; i <= SIZE; i++) facinv[i] = facinv[i - 1] * inv[i];
  return;
}
int N, M;
int S[2010], T[2010];
struct BIT {
  ModInt bit[2010];
  void add(int i, ModInt x) {
    i++;
    while (i <= 2000) {
      bit[i] += x;
      i += i & -i;
    }
    return;
  }
  ModInt sum(int i) {
    i++;
    ModInt res;
    while (i > 0) {
      res += bit[i];
      i -= i & -i;
    }
    return res;
  }
};
BIT bits[2010];
void Add(int i, int j, ModInt x) {
  i++;
  while (i <= 2000) {
    bits[i].add(j, x);
    i += i & -i;
  }
  return;
}
ModInt Sum(int i, int j) {
  i++;
  ModInt res = 0;
  while (i > 0) {
    res += bits[i].sum(j);
    i -= i & -i;
  }
  return res;
}
int main() {
  init();
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> T[i];
  }
  Add(0, 0, ModInt(1ll));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (S[i] == T[j]) {
        Add(i + 1, j + 1, Sum(i, j));
      }
    }
  }
  cout << Sum(N, M) << endl;
  return 0;
}
