#include <bits/stdc++.h>
int main(void) {
  int N = 0;
  std::cin >> N;
  int M = 0;
  std::cin >> M;
  std::vector<int> S(M);
  std::vector<int> c(M);
  for (int i = 0; i < M; i++) {
    std::cin >> S[i] >> c[i];
  }
  int answer = -1;
  bool ok = true;
  if (N == 1) {
    for (int i = 9; i >= 0; i--) {
      for (int m = 0; m < M; m++) {
        int check = i;
        if (check == c[m]) {
          answer = i;
        }
      }
    }
  } else if (N == 2) {
    for (int i = 99; i >= 10; i--) {
      for (int m = 0; m < M; m++) {
        if (S[m] == 1) {
          int check = i / 10;
          if (check != c[m]) {
            ok = false;
          }
        } else if (S[m] == 2) {
          int check = i % 10;
          if (check != c[m]) {
            ok = false;
          }
        }
      }
      if (ok == true) {
        answer = i;
      }
      ok = true;
    }
  } else if (N == 3) {
    for (int i = 999; i >= 100; i--) {
      for (int m = 0; m < M; m++) {
        if (S[m] == 1) {
          int check = i / 10 / 10;
          if (check != c[m]) {
            ok = false;
          }
        } else if (S[m] == 2) {
          int check = i / 10 % 10;
          if (check != c[m]) {
            ok = false;
          }
        } else if (S[m] == 3) {
          int check = i % 10;
          if (check != c[m]) {
            ok = false;
          }
        }
      }
      if (ok == true) {
        answer = i;
      }
      ok = true;
    }
  }
  std::cout << answer;
  return 0;
}
