#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M);
  vector<int> C(M);
  for (int i = 0; i < M; i++) {
    cin >> S.at(i);
    cin >> C.at(i);
  }
  bool F = false;
  int kotae = -1;
  if (N == 1) {
    for (int i = 0; i <= 9; i++) {
      F = false;
      for (int k = 0; k < M; k++) {
        if (i != C.at(k)) {
          F = true;
        }
      }
      if (F == false) {
        kotae = i;
        break;
      }
    }
  }
  if (N == 2) {
    for (int i = 10; i <= 99; i++) {
      F = false;
      for (int k = 0; k < M; k++) {
        if (S.at(k) == 2) {
          if (i != C.at(k)) {
            F = true;
          }
        }
        if (S.at(k) == 1) {
          if (i / 10 != C.at(k)) {
            F = true;
          }
        }
      }
      if (F == false) {
        kotae = i;
        break;
      }
    }
  }
  if (N == 3) {
    for (int i = 100; i <= 999; i++) {
      F = false;
      for (int k = 0; k < M; k++) {
        if (S.at(k) == 3) {
          if (i % 10 != C.at(k)) {
            F = true;
          }
        }
        if (S.at(k) == 2) {
          if ((i / 10) % 10 != C.at(k)) {
            F = true;
          }
        }
        if (S.at(k) == 1) {
          if (i / 100 != C.at(k)) {
            F = true;
          }
        }
      }
      if (F == false) {
        kotae = i;
        break;
      }
    }
  }
  cout << kotae << endl;
}
