#include <bits/stdc++.h>
using namespace std;
const long long N = 200005;
const long long MOD = 998244353;
void solve() {
  long long n, m, f = 1;
  cin >> n >> m;
  long long a[n];
  for (long long i = 0; i < n; i++) a[i] = -1;
  while (m--) {
    long long s, c;
    cin >> s >> c;
    s--;
    if (a[s] == -1)
      a[s] = c;
    else {
      if (a[s] != c) f = 0;
    }
  }
  if (n > 0 && a[0] == 0) {
    cout << "-1";
    return;
  }
  if (f)
    for (long long i = 0; i < n; i++) cout << max(0ll, a[i]);
  else
    cout << "-1";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  while (t--) solve();
  return 0;
}
