#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e3+10;
int n,m;
int f[N],head[N],tot,t[N];
struct node{
int to,nxt,w;
}e[N];
void add(int u,int v,int w){
tot++;
e[tot].to=v;
e[tot].nxt=head[u];
e[tot].w=w;
head[u]=tot;
}
void dfs(int u){
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;
dfs(v);
if(f[v]>=e[i].w){
f[u]+=f[v]-e[i].w;
t[u]+=t[v];
}
}
}
signed main(){
scanf("%lld %lld",&n,&m);
for(int i=1;i<=n-m;i++){
int k;
scanf("%lld",&k);
for(int j=1;j<=k;j++){
int v,w;
scanf("%lld %lld",&v,&w);
add(i,v,w);
}
}
for(int i=n-m+1;i<=n;i++){
scanf("%lld",&f[i]);
t[i]++;
}
dfs(1);
printf("%lld",t[1]);
return 0;
}
刚调完RE就WA了,服了