#include <bits/stdc++.h>
using namespace std;
const int N=100000+5;
int n,m,tot=0;
int a[N],len[N],len2[N];
int b[N]={0};
int pt[N];
bool ok[N]={0};
int lowbit(int x){
return x&(-x);
}
void add(int x,int y){
for (int i=x;i<=n;i+=lowbit(i))len[i]+=y;
return ;
}
int getsum(int x){
int t=0;
for (int i=x;i>0;i-=lowbit(i))t+=len[i];
return t;
}
int main(){
freopen ("windy.in","r",stdin);
freopen ("windy.out","w",stdout);
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++){
scanf("%d",&a[i]);
pt[a[i]]=i;
tot+=i-1-getsum(a[i]);
add(a[i],1);
}
for (int i=1;i<=m;i++){
int t;scanf("%d",&t);
printf("%d\n",tot);
int id=pt[t];ok[id]=1;
for (int j=1;j<id;j++){
if (ok[j]==1)continue;
if (a[j]>t)tot--;
}
for (int j=id+1;j<=n;j++){
if (ok[j]==1)continue;
if (a[j]<t)tot--;
}
}
}