#include <bits/stdc++.h>
using namespace std;
int N, M, S[200], T[200], DP[201][201], s[201][201];
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; ++i) {
    cin >> S[i];
  }
  for (int i = 0; i < M; ++i) {
    cin >> T[i];
  }
  for (int i = 0; i <= M; ++i) {
    s[0][i] = 1;
  }
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= M; ++j) {
      s[i][j] = s[i][j - 1];
      if (S[i - 1] == T[j - 1]) {
        DP[i][j] = s[i - 1][j - 1];
        s[i][j] += DP[i][j];
        s[i][j] %= 1000000007;
      }
    }
    for (int j = 0; j <= M; ++j) {
      s[i][j] += s[i - 1][j];
      s[i][j] %= 1000000007;
    }
  }
  cout << s[N][M] << endl;
}
