#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M), C(M);
  for (int i = 0; i < (M); i++) cin >> S[i] >> C[i];
  int Q = 1;
  if (N == 1) {
    for (int i = 0; i < (9); i++) {
      vector<int> X(1);
      X[0] = i + 1;
      int ans = 1;
      for (int j = 0; j < (M); j++) {
        if (X[S[j] - 1] != C[j]) ans = 0;
      }
      if (ans) {
        cout << i + 1 << endl;
        Q = 0;
        break;
      }
    }
  } else if (N == 2) {
    for (int i = 0; i < (90); i++) {
      vector<int> X(2);
      X[0] = (i + 10) / 10;
      X[1] = (i + 10) % 10;
      int ans = 1;
      for (int j = 0; j < (M); j++) {
        if (X[S[j] - 1] != C[j]) ans = 0;
      }
      if (ans) {
        cout << i + 10 << endl;
        Q = 0;
        break;
      }
    }
  } else {
    for (int i = 0; i < (900); i++) {
      vector<int> X(3);
      X[0] = (i + 100) / 100;
      X[1] = (i + 100) % 100 / 10;
      X[2] = (i + 100) % 10;
      int ans = 1;
      for (int j = 0; j < (M); j++) {
        if (X[S[j] - 1] != C[j]) ans = 0;
      }
      if (ans) {
        cout << i + 100 << endl;
        Q = 0;
        break;
      }
    }
  }
  if (Q) cout << -1 << endl;
}
