#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long linf = 1LL << 62;
const int MAX = 510000;
long long dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
long long dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const double pi = acos(-1);
const double eps = 1e-7;
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
template <typename T1, typename T2>
inline void print2(T1 a, T2 b) {
  cout << a << " " << b << endl;
}
template <typename T1, typename T2, typename T3>
inline void print3(T1 a, T2 b, T3 c) {
  cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;
long long modpow(long long x, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m), c(m);
  for (long long i = 0; i < (m); i++) cin >> s[i] >> c[i];
  long long N = modpow(10, n - 1, mod);
  vector<long long> t(10, 0);
  if (n == 1) {
    for (long long i = 0; i < (10); i++) {
      long long tmp = i;
      long long id = 0;
      while (tmp > 0) {
        t[id] = tmp % 10;
        tmp /= 10;
      }
      for (long long j = 0; j < (m); j++) {
        if (t[n - s[i]] != c[j]) break;
        if (j == m - 1) {
          cout << i << endl;
          return 0;
        }
      }
    }
  } else {
    for (long long i = (N); i < (N * 10); i++) {
      long long tmp = i;
      long long id = 0;
      while (tmp > 0) {
        t[id] = tmp % 10;
        tmp /= 10;
        id++;
      }
      for (long long j = 0; j < (m); j++) {
        if (t[n - s[j]] != c[j]) break;
        if (j == m - 1) {
          cout << i << endl;
          return 0;
        }
      }
      for (long long j = 0; j < (3); j++) t[j] = 0;
    }
  }
  cout << -1 << endl;
}
