#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long N = 0, M = 0;
  cin >> N;
  cin >> M;
  vector<vector<long long>> X(M, vector<long long>(2));
  for (long long i = 0; i < long long(M); i++) cin >> X[i][0] >> X[i][1];
  long long a = -1;
  bool f = false;
  for (long long j = 0; j < long long(1000); j++) {
    long long ans = j;
    bool finished = false;
    for (long long i = 0; i < long long(M); i++) {
      if (N == 1) {
        if (j > 9) finished = true;
        break;
        if (X[i][0] == 1) {
          if (ans != X[i][1]) finished = true;
          break;
        }
      }
      if (N == 2) {
        if (j > 99 || j < 10) finished = true;
        break;
        if (X[i][0] == 2) {
          if (ans % 10 != X[i][1]) finished = true;
          break;
        }
        if (X[i][0] == 1) {
          if (ans / 10 != X[i][1]) finished = true;
          break;
        }
      }
      if (N == 3) {
        if (j < 100) finished = true;
        break;
        if (X[i][0] == 3) {
          if (ans % 10 != X[i][1]) finished = true;
          break;
        }
        if (X[i][0] == 2) {
          if ((ans % 100) / 10 != X[i][1]) finished = true;
          break;
        }
        if (X[i][0] == 1) {
          if (ans / 100 != X[i][1]) finished = true;
          break;
        }
      }
      a = j;
      f = true;
      break;
    }
    if (finished) continue;
    if (f) break;
  }
  cout << a << endl;
  return 0;
}
