#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];
  for (int i = 0; i < n; 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;
    }
  }
  if (ans_ary[f[n]] == 0) {
    ans_ary[f[n]] = 1;
  } else {
    if (flgx[0] == false && flgx[1] == false && flgx[2] == false) {
      for (int i = n - 1; 0 < i; 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 (ans_ary[i] != 0 || flg == true) {
      cout << ans_ary[i];
      flg = true;
    }
  }
  if (flg == false) {
    cout << "-1" << endl;
    return 0;
  }
  cout << endl;
}
