#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long a, b, c, i, j, k;
  cin >> a >> b;
  long line1[a + 1], line2[b + 1];
  line1[0] = 0;
  line2[0] = 0;
  long dp[a + 1][b + 1];
  for (i = 0; i < a; i++) cin >> line1[i + 1];
  for (i = 0; i < b; i++) cin >> line2[i + 1];
  for (i = 0; i < a + 1; i++) {
    for (j = 0; j < b + 1; j++) {
      if (i == 0 || j == 0) {
        dp[i][j] = 1;
        continue;
      }
      if (line1[i] == line2[j]) {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      } else
        dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
      dp[i][j] = dp[i][j] % 1000000007;
    }
  }
  cout << dp[a][b] % 1000000007 << endl;
}
