/*========================
TYPE:
TITLE:
COPYRIGHT:MOSHANGYIN
========================*/
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int size;
int n, m;
int val[3010],head[3010];
int f[3010][3010];
struct Node
{
int v, next, w;
}e[3010];
inline int in()
{
char c=getchar();
int x=0;
while(c<'0'||c>'9')c=getchar();
for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0';
return x;
}
void addedge(int u,int v,int w)
{
e[size].v=v;
e[size].w=w;
e[size].next=head[u];
head[u]=size++;
}
int dfs(int u)
{
for (int i = 1; i <= m; ++i)
{
f[u][i] = -0x3F3F3F3F;
}
if (head[u] == 0)
{
f[u][1] = val[u];
return 1;
}
int sum = 0;
for (int m = head[u]; m ; m = e[m].next)
{
int v = e[m].v, w = e[m].w;
int numLeaf = dfs(v);
sum += numLeaf;
for (int s = sum; s >= 1; --s)
{
for (int k = 0; k <= numLeaf && k <= s; ++k)
{
f[u][s] = max(f[u][s], f[u][s-k] + f[v][k] + w);
}
}
}
return sum;
}
int main()
{
freopen("televi.in","r",stdin);
freopen("televi.out","w",stdout);
n=in(),m=in();
size=1;
for(int i=1;i<=n-m;i++)
{
int x,v,w;
x=in();
while(x--)
{
v=in(),w=in();
addedge(i,v,-w);
}
}
for (int i = n - m + 1; i <= n; ++i)
{
val[i]=in();
}
dfs(1);
for (int i = m; i >= 0; --i)
{
if (f[1][i] >= 0)
{
printf("%d",i);
break;
}
}
}