#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void) {
  int n;
  cin >> n;
  int m;
  cin >> m;
  int ans[3];
  for (int i = 0; i < 3; ++i) {
    ans[i] = 0;
  }
  bool flag = true;
  bool flag1 = false;
  bool flag2 = false;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if (ans[a - 1] != 0 && ans[a - 1] != b) {
      flag = false;
      break;
    }
    if (a - 1 == 0) flag1 = true;
    if (a - 1 == 1) flag2 = true;
    ans[a - 1] = b;
  }
  if (n == 3 && ans[0] == 0 && flag1) flag = false;
  if (n == 3 && !flag1) ans[0] = 1;
  if (n == 2 && !flag2) ans[1] = 1;
  string out;
  if (!flag) {
    cout << "-1" << endl;
  } else {
    for (int i = 3 - n; i < 3; i++) {
      out += to_string(ans[i]);
      cout << out << endl;
    }
  }
  return 0;
}
