#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> S(M);
  vector<int> C(M);
  for (int i = 0; i < (M); i++) {
    cin >> S[i] >> C[i];
  }
  if (N == 1) {
    for (int n = 0; n <= 9; ++n) {
      bool flag = true;
      for (int i = 0; i < (M); i++) {
        if (S[i] == 1 && C[i] != n) {
          flag = false;
        } else {
          flag = false;
        }
      }
      if (flag) {
        cout << n << endl;
        return 0;
      }
    }
  } else if (N == 2) {
    for (int n = 10; n <= 99; ++n) {
      bool flag = true;
      for (int i = 0; i < (M); i++) {
        if (S[i] == 1 && C[i] != (n / 10)) {
          flag = false;
        } else if (S[i] == 2 && C[i] != (n % 10)) {
          flag = false;
        } else {
          flag = false;
        }
      }
      if (flag) {
        cout << n << endl;
        return 0;
      }
    }
  } else {
    for (int n = 100; n <= 999; ++n) {
      bool flag = true;
      for (int i = 0; i < (M); i++) {
        if (S[i] == 1 && C[i] != (n / 100)) {
          flag = false;
        } else if (S[i] == 2 && C[i] != ((n / 10) % 10)) {
          flag = false;
        } else if (S[i] == 3 && C[i] != (n % 100)) {
          flag = false;
        } else {
          flag = false;
        }
      }
      if (flag) {
        cout << n << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
