#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long to, cost;
};
const long long INF = 100000000000000000;
const long long INF2 = 9223372036854775807;
const long long MOD = 1000000007;
long long ceil2(long long a, long long b) {
  if (a % b == 0) {
    return a / b;
  } else {
    return a / b + 1;
  }
}
long long pow2(long long a, long long b) {
  long long r = 1;
  for (long long i = 1; i <= b; i++) {
    r *= a;
  }
  return r;
}
long long Log2(long long a) {
  long long t = 0;
  while (1) {
    if (a == 0 || a == 1) {
      break;
    }
    a /= 2;
    t++;
  }
  return t;
}
long long N, M;
long long A[10], B[10];
long long C[3];
signed main() {
  cin >> N >> M;
  for (long long i = 0; i < (long long)(M); i++) {
    cin >> A[i] >> B[i];
    A[i]--;
  }
  long long R = pow2(10, N + 1) - 1;
  for (long long i = 0; i <= R; i++) {
    deque<long long> v;
    string s = to_string(i);
    for (long long j = 0; j < (long long)(s.size()); j++) {
      v.push_back(s[j] - '0');
    }
    while (v.size() < N) {
      v.push_front(-1);
    }
    bool flag = true;
    for (long long j = 0; j < (long long)(M); j++) {
      if (v[A[j]] != B[j]) {
        flag = false;
      }
    }
    if (flag == true) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
