#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1LL << 61;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n), t(m);
  for (long long i = 0; i < n; i++) cin >> s[i];
  for (long long i = 0; i < m; i++) cin >> t[i];
  vector<vector<long long> > sum(n + 1, vector<long long>(m + 1));
  vector<vector<long long> > dp(n + 1, vector<long long>(m + 1));
  dp[0][0] = 1;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = (dp[i][j] + 1);
      }
      sum[i + 1][j + 1] =
          sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + dp[i + 1][j + 1];
    }
    cout << sum[n][m] << endl;
  }
}
