#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  int a, i;
  int x = 10, y = 10, z = 10, x1 = 0, y1 = 0, z1 = 0;
  for (int j = 0; j < (M); j++) {
    cin >> i >> a;
    if ((i == 1) && (a == 0)) {
      cout << "-1" << endl;
      return 0;
    } else if ((i == 1) && (a != x) && (x1 >= 1)) {
      cout << "-1" << endl;
      return 0;
    } else if ((i == 2) && (a != y) && (y1 >= 1)) {
      cout << "-1" << endl;
      return 0;
    } else if ((i == 3) && (a != z) && (z1 >= 1)) {
      cout << "-1" << endl;
      return 0;
    } else if (i == 1) {
      x = a;
      x1++;
    } else if (i == 2) {
      y = a;
      y1++;
    } else if (i == 3) {
      z = a;
      z1++;
    }
  }
  if ((x == 10) && (N == 1))
    x = 0;
  else if (x == 10)
    x = 1;
  if (y == 10) y = 0;
  if (z == 10) z = 0;
  if (N == 3)
    cout << x << y << z << endl;
  else if (N == 2)
    cout << x << y << endl;
  else if (N == 1)
    cout << x << endl;
  return 0;
}
