#include <bits/stdc++.h>
using namespace std;
long long x[5000], y[5000], dp[5000][5000];
signed main() {
  long long a, b;
  cin >> a >> b;
  for (long long i = 0; i < (a); i++) cin >> x[i];
  for (long long i = 0; i < (b); i++) cin >> y[i];
  for (long long i = 1; i <= a; i++) {
    for (long long j = 1; j <= b; j++) {
      if (x[i - 1] == y[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
      dp[i][j] += dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      dp[i][j] %= (long long)(1000000007);
    }
  }
  cout << dp[a][b] + 1 << endl;
}
