#include <bits/stdc++.h>
using namespace std;
int n, m;
const int MAXN = 2010;
const int MAXM = 2010;
const int INF = 1000000007;
struct BIT {
  long long dat[MAXN][MAXM];
  void update(int x, int y, long long v) {
    v %= INF;
    for (int i = x; i <= n; i += i & -i) {
      for (int j = y; j <= m; j += j & -j) {
        dat[i][j] += v;
        if (dat[i][j] > INF) {
          dat[i][j] %= INF;
        }
      }
    }
  }
  long long qsum(int x, int y) {
    long long res = 0;
    for (int i = x; i > 0; i -= i & -i) {
      for (int j = y; j > 0; j -= j & -j) {
        res += dat[i][j];
      }
      res %= INF;
    }
    return res;
  }
  int qsum(int x0, int y0, int x1, int y1) {
    return qsum(x1, y1) - qsum(x0 - 1, y1) - qsum(x1, y0 - 1) +
           qsum(x0 - 1, y0 - 1);
  }
};
signed main() {
  int N, M;
  cin >> N >> M;
  n = N;
  m = M;
  vector<long long> S(N + 1, -1), T(M + 1, -1);
  for (long long(i) = (0); (i) < (N); (i)++) {
    cin >> S[i + 1];
  }
  for (long long(i) = (0); (i) < (M); (i)++) {
    cin >> T[i + 1];
  }
  BIT DP;
  DP.update(1, 1, 1);
  for (long long(i) = (1); (i) < (N + 1); (i)++) {
    for (long long(j) = (1); (j) < (M + 1); (j)++) {
      if (S[i] == T[j]) {
        long long tmp = DP.qsum(i, j);
        DP.update(i, j, tmp);
      }
    }
  }
  cout << DP.qsum(N + 1, M + 1) << endl;
}
