#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const long long INF = 1e9 + 10;
const long long mod = 998244353;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  long long N, M;
  cin >> N >> M;
  vector<int> S(M), C(M);
  for (int i = 0; i < M; i++) {
    cin >> S[i] >> C[i];
  }
  int A[3];
  for (int x = 1; x < 1000; x++) {
    if (N == 1 && x >= 10) continue;
    if (N == 2 && (x >= 100 || x <= 10)) continue;
    if (N == 3 && (x >= 1000 || x <= 100)) continue;
    A[0] = x % 10;
    A[1] = x % 100 / 10;
    A[2] = x / 100;
    int fail = 0;
    for (int i = 0; i < M; i++) {
      if (A[N - S[i]] != C[i]) {
        fail = 1;
        break;
      }
    }
    if (fail) {
      continue;
    }
    cout << x;
    return 0;
  }
  cout << -1;
  return 0;
}
