// read N1 & N2 using cin
int N1, N2;
cin >> N1;
cin >> N2;
// skip the new line which is after N2 (i.e; 2 value in 1st line)
cin.ignore(numeric_limits<streamsize>::max(), '
');
// now read 3 4 5 elements
int ele;
// 2nd EOF condition may required,
// depending on if you dont have last new-line, and it is end of file.
while ((cin_.peek() != '
') && (cin_.peek() != EOF)) {
cin >> ele;
// do something with ele
}