#include <bits/stdc++.h>
using namespace std;
long modpow(long a, long n, long mod) {
  long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long modinv(long a, long mod) { return modpow(a, mod - 2, mod); }
int main() {
  int N, M;
  cin >> N >> M;
  int s[10], c[10];
  for (int i = 0; (i) < (M); (i)++) cin >> s[i] >> c[i];
  bool flag = true;
  int temp1 = -1;
  for (int i = 0; (i) < (M); (i)++)
    if (s[i] == 1 && temp1 == -1)
      temp1 = c[i];
    else if (s[i] == 1 && temp1 != c[i]) {
      cout << -1 << endl;
      flag = false;
    }
  int temp2 = -1;
  for (int i = 0; (i) < (M); (i)++)
    if (s[i] == 2 && temp2 == -1)
      temp2 = c[i];
    else if (s[i] == 2 && temp2 != c[i]) {
      cout << -1 << endl;
      flag = false;
    }
  int temp3 = -1;
  for (int i = 0; (i) < (M); (i)++)
    if (s[i] == 3 && temp3 == -1)
      temp3 = c[i];
    else if (s[i] == 3 && temp3 != c[i]) {
      cout << -1 << endl;
      flag = false;
    }
  if (flag) {
    if (N == 3) {
      if (temp1 == 0)
        cout << -1 << endl;
      else {
        if (temp1 == -1) temp1 = 1;
        if (temp2 == -1) temp2 = 0;
        if (temp3 == -1) temp3 = 0;
        cout << temp1 * 100 + temp2 * 10 + temp3 << endl;
      }
    } else if (N == 2) {
      if (temp1 != -1 || temp2 == 0)
        cout << -1 << endl;
      else {
        if (temp2 == -1) temp2 = 1;
        if (temp3 == -1) temp3 = 0;
        cout << temp2 * 10 + temp3 << endl;
      }
    } else {
      if (temp1 != -1 || temp2 != -1)
        cout << -1 << endl;
      else {
        if (temp3 == -1) temp3 = 0;
        cout << temp3 << endl;
      }
    }
  }
  return 0;
}
