#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a, b, c, d;
  int flag = -1, res;
  for (int i = 1; i <= 4; i++) {
    cin >> a >> b >> c >> d;
    if (flag != -1) continue;
    if (min(a, b) + min(c, d) <= n) flag = i;
    res = min(a, b);
  }
  if (flag != -1) {
    cout << flag << " " << res << " " << n - res << endl;
  } else
    cout << flag << endl;
  return 0;
}
