#include <bits/stdc++.h>
using namespace std;
class RSAQ {
 public:
  const long long mod = 1e9 + 7;
  struct D {
    long long value;
    D() : value(0) {}
    D(long long value) : value(value) {}
    bool operator<(D a) const { return value < a.value; }
  };
  struct T {
    long long type;
    long long value;
    T() : type(0), value(0) {}
    T(long long type, long long value) : type(type), value(value) {}
  };
  long long n, n_;
  vector<D> dat;
  vector<T> td;
  D returnD = D(0);
  RSAQ() { n = -1; }
  RSAQ(long long n_) : n_(n_) {
    n = 1;
    while (n < n_) n *= 2;
    td.resize(2 * n - 1, T());
    dat.resize(2 * n - 1, D());
  }
  inline D merge(const D a, const D b) const {
    return (a.value + b.value) % mod;
  }
  void delay(long long k, long long len) {
    if (td[k].type == 0) return;
    long long type = td[k].type;
    long long v = td[k].value;
    td[k].type = 0;
    td[k].value = 0;
    len /= 2;
    {
      long long l = k * 2 + 1;
      dat[l].value += v * len;
      td[l].type = type;
      td[l].value += v;
    }
    {
      long long r = k * 2 + 2;
      dat[r].value += v * len;
      td[r].type = type;
      td[r].value += v;
    }
  }
  D write(long long k, D x, long long len) {
    dat[k].value += x.value * len;
    td[k].type = 1;
    td[k].value += x.value;
    return dat[k];
  }
  D dfs(long long a, long long b, D x, bool flag, long long k, long long l,
        long long r) {
    if (r <= a || b <= l) return flag ? dat[k] : returnD;
    if (a <= l && r <= b) return flag ? write(k, x, r - l) : dat[k];
    delay(k, r - l);
    D vl = dfs(a, b, x, flag, k * 2 + 1, l, (l + r) / 2);
    D vr = dfs(a, b, x, flag, k * 2 + 2, (l + r) / 2, r);
    return flag ? (dat[k] = merge(vl, vr)) : merge(vl, vr);
  }
  void add(long long l, long long r, long long x) {
    assert(l <= r);
    assert(0 <= l && l <= n);
    assert(0 <= r && r <= n);
    dfs(l, r, D(x), true, 0, 0, n);
  }
  long long get(long long l, long long r) {
    assert(l <= r);
    assert(0 <= l && l <= n);
    assert(0 <= r && r <= n);
    D res = dfs(l, r, D(), false, 0, 0, n);
    return res.value;
  }
};
const long long N = 2005;
const long long M = 2005;
const long long mod = 1e9 + 7;
long long n, m;
long long A[N], B[M];
long long dp[N][M];
signed main() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> A[i];
  for (long long i = 0; i < m; i++) cin >> B[i];
  RSAQ rmq(n);
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (A[i] == B[j]) {
        dp[i][j] = rmq.get(0, j) + 1;
        dp[i][j] %= mod;
      }
    }
    for (long long j = 0; j < m; j++) {
      if (A[i] == B[j]) {
        rmq.add(j, j + 1, dp[i][j]);
      }
    }
  }
  long long ans = (rmq.get(0, m) + 1) % mod;
  cout << ans << endl;
  return 0;
}
