#include<bits/stdc++.h>usingnamespace std;#define _rep(i, a, b) for (int i = (a); i <= (b); ++i)#define _rev(i, a, b) for (int i = (a); i >= (b); --i)#define _for(i, a, b) for (int i = (a); i < (b); ++i)#define _rof(i, a, b) for (int i = (a); i > (b); --i)#define oo 0x3f3f3f3f#define ll long long#define db double#define eps 1e-8#define bin(x) cout << bitset<10>(x) << endl;#define what_is(x) cerr << #x << " is " << x << "s" << endl;#define met(a, b) memset(a, b, sizeof(a))#define all(x) x.begin(), x.end()#define pii pair<int, int>constint maxn =120;int n, m, pro[maxn], cnt =1, d[maxn], head[maxn], take[maxn], s, t, sum;char buf[10000];struct node
{int nxt, to, cost;} way[6000];voidaddedge(int from,int to,int cost){
way[++cnt].cost = cost;
way[cnt].to = to;
way[cnt].nxt = head[from];
head[from]= cnt;}intnxt(){int ret;scanf("%d",&ret);return ret;}boolbfs(){met(d,0);
queue<int> q;
q.push(s);
d[s]=1;while(!q.empty()){int cur = q.front();
q.pop();for(int i = head[cur]; i; i = way[i].nxt){int to = way[i].to, cost = way[i].cost;if(!d[to]&& cost){
d[to]= d[cur]+1;if(to == t)return1;
q.push(to);}}}return0;}intdfs(int cur,int flow){if(cur == t)return flow;int rest = flow, k;for(int i = head[cur]; i && rest; i = way[i].nxt){int to = way[i].to, cost = way[i].cost;if(d[to]== d[cur]+1&& cost){
k =dfs(to,min(cost, rest));if(!k)
d[to]=0;
way[i].cost -= k;
way[i ^1].cost += k;
rest -= k;}}return flow - rest;}voidDinic(){int ans =0;while(bfs())
ans +=dfs(s, oo);_rep(i,1, m)if(d[i]>0)cout << i <<" ";
cout << endl;_rep(i, m+1, m+n)if(d[i]>0)cout << i - m <<" ";
cout << endl;
cout << sum - ans << endl;}intmain(){
m =nxt(), n =nxt();
t = n + m +3;_rep(i,1, m){
pro[i]=nxt();
sum += pro[i];met(buf,0);
cin.getline(buf,10000);int ulen =0, tmp;while(sscanf(buf + ulen,"%d",&tmp)==1){addedge(i, tmp + m, oo),addedge(tmp + m, i,0);if(tmp ==0)
ulen++;else{while(tmp){
tmp /=10;
ulen++;}}
ulen++;}}_rep(i,1+ m, n + m)
take[i]=nxt();_rep(i,1, m)addedge(s, i, pro[i]),addedge(i, s,0);_rep(i,1+ m, m + n)addedge(i, t, take[i]),addedge(t, i,0);Dinic();}