#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b, c, flag, fa, fb, fc, fd;
  int x, y;
  flag = 0;
  a = -1;
  b = -1;
  c = -1;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    if (x == 1) {
      if (a == -1) {
        a = y;
      } else {
        if (a != y) flag = 1;
      }
    }
    if (x == 2) {
      if (b == -1) {
        b = y;
      } else {
        if (b != y) flag = 1;
      }
    }
    if (x == 3) {
      if (c == -1) {
        c = y;
      } else {
        if (c != y) flag = 1;
      }
    }
  }
  if (flag) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 1) {
    if (a == -1) a = 0;
    cout << a << endl;
    return 0;
  }
  if (n == 2) {
    if (b == -1) b = 0;
    if (a == -1) a = 1;
    if (a == 0) {
      cout << -1 << endl;
      return 0;
    } else {
      cout << a << b << endl;
      return 0;
    }
  }
  if (a == -1) a = 0;
  if (b == -1) b = 0;
  if (c == -1) c = 0;
  if (a == 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << a << b << c << endl;
  return 0;
}
