#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.at(i) >> c.at(i);
  }
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    vec.at(i) = 0;
  }
  int sw = 0;
  int sw1 = 0;
  int sw2 = 0;
  int sw3 = 0;
  int sw4 = 0;
  int sw5 = 0;
  for (int i = 0; i < M; i++) {
    if (N == 1) {
      if (sw > 0 && vec.at(0) != c.at(i)) {
        cout << "-1" << endl;
        return 0;
      } else {
        vec.at(0) = c.at(i);
        sw++;
      }
    } else if (N == 2) {
      if (s.at(i) == 1) {
        if (sw1 > 0 && vec.at(0) != c.at(i)) {
          cout << "-1" << endl;
          return 0;
        } else {
          vec.at(0) = c.at(i);
          sw1++;
        }
      } else {
        if (sw2 > 0 && vec.at(1) != c.at(i)) {
          cout << "-1" << endl;
          return 0;
        } else {
          vec.at(1) = c.at(i);
          sw2++;
        }
      }
    } else {
      if (s.at(i) == 1) {
        if (sw3 > 0 && vec.at(0) != c.at(i)) {
          cout << "-1" << endl;
          return 0;
        } else {
          vec.at(0) = c.at(i);
          sw3++;
        }
      } else if (s.at(i) == 2) {
        if (sw4 > 0 && vec.at(1) != c.at(i)) {
          cout << "-1" << endl;
          return 0;
        } else {
          vec.at(1) = c.at(i);
          sw4++;
        }
      } else {
        if (sw5 > 0 && vec.at(2) != c.at(i)) {
          cout << "-1" << endl;
          return 0;
        } else {
          vec.at(2) = c.at(i);
          sw5++;
        }
      }
    }
  }
  for (int i = 0; i < 3; i++) {
    if (N == 2) {
      if (vec.at(0) == 0) {
        cout << "-1" << endl;
        return 0;
      }
    }
    if (N == 3) {
      if (vec.at(0) == 0) {
        cout << "-1" << endl;
        return 0;
      }
    }
    cout << vec.at(i);
  }
}
