#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int check = 0;
  int keta1 = 1;
  int keta2 = 0;
  int keta3 = 0;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int k = 0; k < m; k++) {
    cin >> s[k] >> c[k];
  }
  for (int i = 0; i < m; i++) {
    for (int j = 1; j < m; j++) {
      if (s[i] == s[j]) {
        if (!(c[i] == c[j])) {
          check = 1;
        }
      }
    }
    if (s[i] == 1) {
      if (c[i] == 0) {
        check = 1;
      }
      keta1 = c[i];
    }
    if (s[i] == 2) {
      keta2 = c[i];
    }
    if (s[i] == 3) {
      keta3 = c[i];
    }
  }
  if (check == 0) {
    cout << keta1 << keta2 << keta3 << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
