#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 62) - 1;
int main(void) {
  int n, m;
  vector<int> s, c;
  int i, j;
  bool flag;
  int b, g;
  cin >> n >> m;
  s.resize(m);
  c.resize(m);
  for ((i) = (0); (i) < (m); ++(i)) {
    cin >> s[i] >> c[i];
  }
  if (n == 1) {
    b = 0;
    g = 10;
  }
  if (n == 2) {
    b = 10;
    g = 100;
  }
  if (n == 3) {
    b = 100;
    g = 1000;
  }
  for ((i) = (b); (i) < (g); ++(i)) {
    flag = true;
    for ((j) = (0); (j) < (m); ++(j)) {
      if (s[j] == 1) {
        if (i / 100 != c[j]) {
          flag = false;
        }
      }
      if (s[j] == 2) {
        if ((i % 100) / 10 != c[j]) {
          flag = false;
        }
      }
      if (s[j] == 3) {
        if (i % 10 != c[j]) {
          flag = false;
        }
      }
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
