#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, k, l;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  bool flag = true, A = false, B = false, C = false;
  if (N == 1) {
    k = 0;
    l = 10;
    A = true;
  } else if (N == 2) {
    k = 10;
    l = 100;
    B = true;
  } else if (N == 3) {
    k = 100;
    l = 1000;
    C = true;
  }
  for (int j = k; j < l; j++) {
    flag = true;
    for (int i = 0; i < M; i++) {
      if (C) {
        if (s.at(i) == 1) {
          if (j / 100 != c.at(i)) {
            flag = false;
          }
        } else if (s.at(i) == 2) {
          if (j / 10 != c.at(i)) {
            flag = false;
          }
        } else if (s.at(i) == 3) {
          if (j % 10 != c.at(i)) {
            flag = false;
          }
        }
      } else if (B) {
        if (s.at(i) == 1) {
          if (j / 10 != c.at(i)) {
            flag = false;
          }
        } else {
          if (j % 10 != c.at(i)) {
            flag = false;
          }
        }
      } else if (A) {
        if (s.at(i) == 1) {
          if (j != c.at(i)) {
            flag = false;
          }
        }
      }
    }
    if (flag) {
      cout << j << endl;
      break;
    }
  }
  if (!flag) {
    cout << -1 << endl;
  }
}
