#include using namespace std; using ll=long long; using Graph=vector>; #define INF 1000000000 int main(){ int N,K; cin>>N>>K; vector A(N); vector M(N); vector> B(N); for(int i=0;i>A[i]>>M[i]; B[i].resize(M[i]); for(int j=0;j>B[i][j]; B[i][j]--; } } vector dp(N+1,0); for(int i=0;i(dp[i+1],dp[B[i][j]+1]+A[i]-A[B[i][j]]); } } cout<