#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  bool nothing = false;
  vector<int> num(N);
  for (int i = 0; i < N; i++) {
    num.at(i) = 10;
  }
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if ((N == 3 || N == 2) && s == 1 && c == 0) {
      nothing = true;
      break;
    }
    if (num.at(s - 1) != 10 && num.at(s - 1) != c) {
      nothing = true;
      break;
    }
    num.at(s - 1) = c;
  }
  if (nothing) {
    cout << "-1" << endl;
  } else {
    if (N == 1) {
      cout << num.at(0) << endl;
    } else if (N == 2) {
      if (num.at(0) != 10 && num.at(1) == 10) {
        num.at(1) = 0;
        cout << num.at(0) << num.at(1) << endl;
      } else if (num.at(0) == 10 && num.at(1) != 10) {
        num.at(0) = 1;
        cout << num.at(0) << num.at(1) << endl;
      } else {
        cout << num.at(0) << num.at(1) << endl;
      }
    } else if (N == 3) {
      if (num.at(0) != 10 && num.at(1) == 10 && num.at(2) == 10) {
        num.at(1) = 0;
        num.at(2) = 0;
        cout << num.at(0) << num.at(1) << num.at(2) << endl;
      } else if (num.at(0) == 10 && num.at(1) != 10 && num.at(2) == 10) {
        num.at(0) = 1;
        num.at(2) = 0;
        cout << num.at(0) << num.at(1) << num.at(2) << endl;
      } else if (num.at(0) == 10 && num.at(1) == 10 && num.at(2) != 10) {
        num.at(0) = 1;
        num.at(1) = 0;
        cout << num.at(0) << num.at(1) << num.at(2) << endl;
      } else if (num.at(0) != 10 && num.at(1) != 10 && num.at(2) == 10) {
        num.at(2) = 0;
        cout << num.at(0) << num.at(1) << num.at(2) << endl;
      } else if (num.at(0) != 10 && num.at(1) == 10 && num.at(2) != 10) {
        num.at(1) = 0;
        cout << num.at(0) << num.at(1) << num.at(2) << endl;
      } else if (num.at(0) == 10 && num.at(1) != 10 && num.at(2) != 10) {
        num.at(0) = 1;
        cout << num.at(0) << num.at(1) << num.at(2) << endl;
      } else if (num.at(0) == 10 && num.at(1) == 10 && num.at(2) == 10) {
        num.at(0) = 1;
        num.at(1) = 0;
        num.at(2) = 0;
        cout << num.at(0) << num.at(1) << num.at(2) << endl;
      } else {
        cout << num.at(0) << num.at(1) << num.at(2) << endl;
      }
    }
  }
}
