#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, s, c, x, y, z, countx, county, countz;
  x = -1;
  y = -1;
  z = -1;
  countx = 0;
  county = 0;
  countz = 0;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    cin >> s >> c;
    if (s == 1) {
      countx += 1;
      if (countx == 1) {
        x = x + 1;
        x += c;
      } else {
        if (c != x) {
          cout << "-1" << endl;
          return 0;
        }
      }
    }
    if (s == 2) {
      county += 1;
      if (county == 1) {
        y = y + 1;
        y += c;
      } else {
        if (c != y) {
          cout << "-1" << endl;
          return 0;
        }
      }
    }
    if (s == 3) {
      countz += 1;
      if (countz == 1) {
        z = z + 1;
        z += c;
      } else {
        if (c != z) {
          cout << "-1" << endl;
          return 0;
        }
      }
    }
  }
  if (n == 1) {
    if (x == -1) {
      x = 1;
      cout << x << endl;
      return 0;
    } else {
      cout << x << endl;
      return 0;
    }
  }
  if (n == 2 && ((x * 10 + y) != 0)) {
    if (x == -1) {
      x = 1;
      cout << x * 10 + y << endl;
      return 0;
    } else {
      cout << x * 10 + y << endl;
      return 0;
    }
  }
  if (n == 3 && ((x * 100 + y * 10 + z) != 0)) {
    if (x == -1) {
      x = 1;
      cout << x * 100 + y * 10 + z << endl;
      return 0;
    } else {
      cout << x * 100 + y * 10 + z << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
}
