#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;
class FenwickTree2D {
  int M, N;
  std::vector<std::vector<ll>> bit;

 public:
  FenwickTree2D(int _m, int _n)
      : M(_m), N(_n), bit(M + 1, std::vector<ll>(N + 1, 0)) {}
  void add(int a, int b, ll w) {
    for (int x = a; x <= M; x += x & -x)
      for (int y = b; y <= N; y += y & -y) {
        bit[x][y] += w;
        bit[x][y] %= mod;
      }
  }
  ll sum(int a, int b) {
    ll ret = 0;
    for (int x = a; x > 0; x -= x & -x)
      for (int y = b; y > 0; y -= y & -y) {
        ret += bit[x][y];
        ret %= mod;
      }
    return ret;
  }
  ll sum(int a, int b, int c, int d) {
    ll ret = sum(c, d);
    ret = (ret + mod - sum(c, b - 1)) % mod;
    ret = (ret + mod - sum(a - 1, d)) % mod;
    ret += sum(a - 1, b - 1);
    return ret % mod;
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  FenwickTree2D dp(n + 2, m + 2);
  dp.add(1, 1, 1);
  vector<int> s(n + 1, 0), t(m + 1, 0);
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= m; i++) cin >> t[i];
  ll ret = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i] != t[j]) continue;
      dp.add(i + 1, j + 1, dp.sum(1, 1, i, j));
      ret += dp.sum(i + 1, j + 1, i + 1, j + 1);
      ret %= mod;
    }
  }
  cout << ret << endl;
}
