#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  int f[n];
  int ans_ary[n];
  bool flgx[n];
  if (n == 0) {
    n = 1;
  }
  for (int i = 0; i < 3; i++) {
    f[i] = n - i;
    ans_ary[i] = 0;
    flgx[i] = false;
  }
  for (int i = 0; i < m; i++) {
    if (ans_ary[s[i] - 1] == 0 || ans_ary[s[i] - 1] == c[i]) {
      ans_ary[s[i] - 1] = c[i];
      flgx[s[i] - 1] = true;
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << ans_ary[0] << " " << ans_ary[1] << " " << ans_ary[2] << endl;
  cout << flgx[0] << " " << flgx[1] << " " << flgx[2] << endl;
  if ((flgx[0] == false && flgx[1] == false && flgx[2] == false &&
       n - 1 != 0) ||
      (ans_ary[0] == 0 && ans_ary[1] == 0 && ans_ary[2] == 0 &&
       flgx[0] != true && n - 1 != 0)) {
    for (int i = 0; 0 < n; i++) {
      if (flgx[i] == false) {
        ans_ary[i] = 1;
        break;
      }
    }
  }
  cout << ans_ary[0] << " " << ans_ary[1] << " " << ans_ary[2] << endl;
  bool flg = false;
  for (int i = 0; i < n; i++) {
    if ((i == n - 1 && ans_ary[n - 1] == 0 && flgx[3 - n] != true) ||
        ans_ary[i] != 0 || flg == true) {
      cout << ans_ary[i];
      flg = true;
    }
  }
  if (flg == false) {
    cout << "-1" << endl;
    return 0;
  }
  cout << endl;
}
