#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}
const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);
void solve(long long N, long long M, std::vector<long long> s,
           std::vector<long long> c) {
  vector<ll> ans(N, -1);
  for (ll i = 0; i < M; i++) {
    ll idx = (s[i] - 1);
    if (ans[idx] == -1 or ans[idx] == c[i]) {
      ans[idx] = c[i];
    } else {
      cout << -1 << endl;
      return;
    }
  }
  if (N > 1 and ans[0] == 0) {
    cout << -1 << endl;
    return;
  }
  if (ans[0] == -1) ans[0] = 1;
  for (ll i = 1; i < N; i++) {
    if (ans[i] == -1) ans[i] = 0;
  }
  for (ll i = 0; i < N; i++) {
    cout << ans[i];
  }
  cout << endl;
  return;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  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 (ll i = 0; i < M; i++) {
    scanf("%lld", &s[i]);
    scanf("%lld", &c[i]);
  }
  solve(N, M, std::move(s), std::move(c));
  return 0;
}
