#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
int main() {
  int N, M;
  cin >> N >> M;
  vi s(M), c(M);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  int maxN, minN;
  if (N == 1) {
    maxN = 9;
    minN = 1;
  }
  if (N == 2) {
    maxN = 99;
    minN = 10;
  }
  if (N == 3) {
    maxN = 999;
    minN = 100;
  }
  bool ans;
  for (int i = minN; i <= maxN; i++) {
    ans = true;
    vi a(4);
    a[3] = i % 10;
    a[2] = (i / 10) % 10;
    a[1] = i / 100;
    for (int j = 0; j < M; j++) {
      if (a[s[j]] != c[j]) ans = false;
      if (ans == false) break;
    }
    if (ans == true) {
      cout << i << endl;
      break;
    }
  }
  if (!ans) cout << -1 << endl;
  return 0;
}
