#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  long long c = gcd(a, b);
  return ((a / c) * (b / c) * c);
}
const long long INF = 1e18 + 7;
const long long MOD = 1e9 + 7;
template <typename T>
struct twodimBIT {
 private:
  vector<vector<T> > array;
  const int n;
  const int m;

 public:
  twodimBIT(int _n, int _m)
      : array(_n + 1, vector<T>(_m + 1, 0)), n(_n), m(_m) {}
  T sum(int x, int y) {
    T s = 0;
    for (int i = x; i > 0; i -= i & (-i))
      for (int j = y; j > 0; j -= j & (-j)) s += array[i][j];
    return s;
  }
  T sum(int x1, int y1, int x2, int y2) {
    return sum(x2, y2) - sum(x1 - 1, y2) - sum(x2, y1 - 1) +
           sum(x1 - 1, y1 - 1);
  }
  void add(int x, int y, T k) {
    for (int i = x; i <= n; i += i & (-i))
      for (int j = y; j <= m; j += j & (-j)) array[i][j] += k;
  }
};
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> S(N), T(M), s(100001, 0);
  for (long long i = long long(0); i < long long(N); ++i) cin >> S[i];
  for (long long i = long long(0); i < long long(M); ++i) cin >> T[i];
  twodimBIT<long long> tb(N + 1, M + 1);
  long long ans = 1;
  for (long long i = long long(0); i < long long(N); ++i) {
    for (long long j = long long(0); j < long long(M); ++j) {
      if (S[i] == T[j]) {
        long long x = tb.sum(i, j);
        (ans += x + 1) %= MOD;
        tb.add(i + 1, j + 1, x + 1);
        (s[S[i]] += x) %= MOD;
      }
    }
  }
  cout << ans << endl;
}
