#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, M;
  cin >> N >> M;
  int s, c;
  int a = 0;
  int b = 0;
  int x = 0;
  for (int i = 0; i < (M); i++) {
    cin >> s >> c;
    if (c == 0 && s == N) {
      cout << -1 << endl;
      return 0;
    }
    if (s == 3) {
      if (a == 0) {
        a = c;
      } else {
        if (a != c) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
    if (s == 2) {
      if (b == 0) {
        b = c;
      } else {
        if (b != c) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
    if (s == 1) {
      if (x == 0) {
        x = c;
      } else {
        if (x != c) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
  }
  if (N == 3 && x == 0) {
    cout << -1 << endl;
    return 0;
  } else if (N == 2 && b == 0) {
    cout << -1 << endl;
    return 0;
  } else if (N == 1 && a == 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << x * 100 + b * 10 + a << endl;
}
