#include <bits/stdc++.h>
using namespace std;
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;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int INF = 1e9;
const long long LLINF = 1e16;
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (long long i = 0, i_len = (m); i < i_len; ++i) {
    cin >> s[i] >> c[i];
  }
  bool exist = true;
  for (long long i = 0, i_len = (m - 1); i < i_len; ++i) {
    for (long long j = i + 1, j_len = (m); j < j_len; ++j) {
      if (s[i] == s[j] && c[i] != c[j]) {
        exist = false;
      }
    }
  }
  if (!exist) {
    cout << -1 << endl;
    return 0;
  }
  int zdigit = n + 1;
  int nz = n + 1;
  for (long long i = 0, i_len = (m); i < i_len; ++i) {
    if (c[i] == 0 && s[i] < zdigit) {
      zdigit = s[i];
    } else if (c[i] != 0 && s[i] < nz) {
      nz = s[i];
    }
  }
  if (zdigit < nz && !(zdigit == n && nz == n + 1)) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 1 && zdigit == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> ans(n, 0);
  for (long long i = 0, i_len = (m); i < i_len; ++i) {
    ans[s[i] - 1] = c[i];
  }
  ans[0] = max(ans[0], 1);
  for (long long i = 0, i_len = (n); i < i_len; ++i) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
