#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  int c[m];
  int x = -1, y = -1, z = -1;
  bool no = 0;
  bool nx = 0;
  bool ny = 0;
  bool nz = 0;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1) {
      if (x == -1 || c[i] == x) {
        x = c[i];
        if (c[i] == 0) nx = 1;
      } else {
        no = true;
      }
    } else if (s[i] == 2) {
      if (y == -1 || c[i] == y) {
        y = c[i];
        if (c[i] == 0) ny = 1;
      } else {
        no = true;
      }
    } else if (s[i] == 3) {
      if (z == -1 || c[i] == z) {
        z = c[i];
        if (c[i] == 0) nz = 1;
      } else {
        no = true;
      }
    }
  }
  if (no == 0) {
    if (n == 3) {
      if (nx == 0) {
        if (x == -1) x = 1;
        if (y == -1) y = 0;
        if (z == -1) z = 0;
        cout << x << y << z << endl;
      } else
        cout << -1 << endl;
    }
    if (n == 2) {
      if (ny == 0) {
        if (y == -1) y = 1;
        if (z == -1) z = 0;
        cout << y << z << endl;
      } else
        cout << -1 << endl;
    }
    if (n == 1) {
      if (z == -1) z = 1;
      cout << z << endl;
    }
  } else
    cout << -1 << endl;
}
