#include <bits/stdc++.h>
using namespace std;
uint32_t dp[2001][2001] = {0};
uint32_t ss[2001] = {};
uint32_t ts[2001] = {};
static const uint32_t kRem = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%u", &ss[i]);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%u", &ts[i]);
  }
  for (int i = 0; i <= n; i++) {
    dp[i][0] = 1;
  }
  for (int j = 0; j <= m; j++) {
    dp[0][j] = 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      uint32_t val = dp[i][j - 1];
      if (ss[i] == ts[j]) {
        val += dp[i - 1][j - 1];
      }
      val += (dp[i - 1][j] - dp[i - 1][j - 1]);
      val %= kRem;
      if (val < 0) val += kRem;
      dp[i][j] = val;
    }
  }
  printf("%d\n", dp[n][m]);
  return 0;
}
