#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  int answer;
  cin >> N >> M;
  map<int, int> sc;
  int s, c;
  int sTemp, cTemp;
  string ansStr = "";
  bool ngFlag = false;
  for (int i = 0; i < N; i++) {
    ansStr += "0";
  }
  for (int i = 0; i < M; i++) {
    cin >> sTemp >> cTemp;
    if (sTemp == s) {
      if (cTemp != c) {
        ngFlag = true;
      }
    }
    c = cTemp;
    s = sTemp;
    sc.insert(make_pair(s, c));
  }
  if (N > 1 && sc[1] == 0) {
    ngFlag = true;
  }
  if (!ngFlag) {
    if (N == 1) {
      answer = sc[1];
    } else if (N == 2) {
      answer = sc[1] * 10 + sc[2];
    } else if (N == 3) {
      answer = sc[1] * 100 + sc[2] * 10 + sc[3];
    }
    if (M == 0) {
      if (N == 1) {
        answer = 0;
      } else if (N == 2) {
        answer = 10;
      } else if (N == 3) {
        answer = 100;
      }
    }
  } else {
    answer = -1;
  }
  cout << answer << endl;
  return 0;
}
