#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
void solve(long long N, long long M, std::vector<long long> s,
           std::vector<long long> c) {
  vector<int> n(N);
  vector<bool> b(N);
  for (ll i = 0, i_len = (M); i < i_len; ++i) {
    if ((b[s[i] - 1] && n[s[i] - 1] != c[i]) || (s[i] == 1 && c[i] == 0)) {
      cout << -1 << endl;
      ;
      return;
    }
    b[s[i] - 1] = true;
    n[s[i] - 1] = c[i];
  }
  if (N >= 2 && n[0] == 0) n[0] = 1;
  for (ll i = 0, i_len = (N); i < i_len; ++i) {
    cout << n[i];
  }
  cout << endl;
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> s(M);
  std::vector<long long> c(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &s[i]);
    scanf("%lld", &c[i]);
  }
  solve(N, M, std::move(s), std::move(c));
  return 0;
}
