#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
using P = pair<ll, ll>;
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;
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  fill((T *)array, (T *)(array + N), val);
}
const ll MOD = 100000007;
const ll INF = 10e9;
ll dx[4] = {1, -1, 0, 0};
ll dy[4] = {0, 0, 1, -1};
ll ddx[8] = {1, 1, 1, -1, -1, -1, 0, 0};
ll ddy[8] = {0, 1, -1, 0, 1, -1, 1, -1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  ;
  ll M;
  cin >> M;
  ;
  vector<ll> S(M);
  vector<ll> C(M);
  for (ll i = 0; i < (int)(M); i++) {
    cin >> S[i] >> C[i];
  };
  vector<ll> ans(N, INF);
  for (ll i = 0; i < (int)(M); i++) {
    if ((ans.at(S.at(i) - 1) != INF && ans.at(S.at(i) - 1) != C.at(i)) ||
        (S.at(i) == 1 && C.at(i) == 0LL)) {
      cout << -1 << endl;
      ;
      return 0;
    } else
      ans.at(S.at(i) - 1) = C.at(i);
  }
  for (ll i = 0; i < (int)(N); i++) {
    if (i == 0 && ans.at(i) == INF) {
      cout << 1;
      continue;
    }
    if (ans.at(i) == INF)
      cout << 0;
    else
      cout << ans.at(i);
  }
  cout << "" << endl;
  ;
}
