#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 ans = -1;
  if (N == 1) {
    for (int i = 9; i >= 0; i--) {
      for (int j = 0; j < M; ++j) {
        if (i == c[j]) {
          ans = i;
        }
      }
    }
  }
  if (N == 2) {
    for (int i = 99; i >= 10; i--) {
      bool ok = true;
      for (int j = 0; j < M; ++j) {
        if (s[j] == 1) {
          if (!(i >= 10 * c[j] && i < 10 * (c[j] + 1))) ok = false;
        }
        if (s[j] == 2) {
          if (i % 10 != c[j]) ok = false;
        }
      }
      if (ok) ans = i;
    }
  }
  if (N == 3) {
    for (int i = 999; i >= 100; i--) {
      bool ok = true;
      for (int j = 0; j < M; ++j) {
        if (s[j] == 1) {
          if (!(i >= 100 * c[j] && i < 100 * (c[j] + 1))) ok = false;
        }
        if (s[j] == 2) {
          if (!(i % 100 >= 10 * c[j] && i % 100 < 10 * (c[j] + 1))) ok = false;
        }
        if (s[j] == 3) {
          if (i % 10 != c[j]) ok = false;
        }
      }
      if (ok) ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}
