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