#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> vec(M, vector<int>(2));
  for (int i = 0; i < (int)(M); i++)
    for (int j = 0; j < (int)(2); j++) cin >> vec[i][j];
  int x;
  if (M == 0) x = 0;
  int keta1;
  int amari1;
  int keta2;
  int amari2;
  int keta3;
  bool ok = true;
  for (int i = 0; i < (int)(1000); i++) {
    if (i == 700) {
      int a = 0;
    }
    keta1 = i / 100;
    amari1 = i % 100;
    keta2 = amari1 / 10;
    amari2 = amari1 % 10;
    keta3 = amari2;
    if (N == 3 && 99 < i && i < 1000) {
      for (int j = 0; j < (int)(M); j++) {
        if (vec[j][0] == 1) {
          if (vec[j][1] == 0) {
            ok = false;
            break;
          } else if (keta1 != vec[j][1]) {
            ok = false;
            break;
          } else
            ok = true;
        }
        if (vec[j][0] == 2) {
          if (vec[j][1] == 0) {
            ok = false;
            break;
          } else if (keta2 != vec[j][1]) {
            ok = false;
            break;
          } else
            ok = true;
        }
        if (vec[j][0] == 3) {
          if (keta3 != vec[j][1]) {
            ok = false;
            break;
          } else
            ok = true;
        }
      }
    } else if (N == 2 && 9 < i && i < 100) {
      for (int k = 0; k < (int)(M); k++) {
        if (vec[k][0] == 1) {
          if (vec[k][1] == 0) {
            ok = false;
            break;
          } else if (keta1 != vec[k][1]) {
            ok = false;
            break;
          } else
            ok = true;
        }
        if (vec[k][0] == 2) {
          if (keta2 != vec[k][1]) {
            ok = false;
            break;
          } else
            ok = true;
        }
      }
    } else if (N == 1 && i < 9) {
      for (int l = 0; l < (int)(M); l++) {
        if (vec[l][0] == 1) {
          if (keta1 != vec[l][1]) {
            ok = false;
            break;
          } else
            ok = true;
        }
      }
    } else
      continue;
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
