#include <bits/stdc++.h>
using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX(1LL << 60);
const ll MOD(1000000007);
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vector<ll> s(m), c(m);
  for (ll i = (0); i < (m); i++) {
    ll t;
    cin >> t >> c[i];
    --t, s[i] = t;
  }
  string num;
  for (ll i = (0); i < (n); i++) num += '-';
  for (ll i = (0); i < (m); i++) {
    if (num[s[i]] == '-')
      num[s[i]] = c[i] + '0';
    else if (num[s[i]] - '0' > c[i])
      num[s[i]] = c[i] + '0';
  }
  for (ll i = (0); i < (n); i++)
    if (num[i] == '-') num[i] = '0';
  if (n == 1 && num[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  if (n == 2 && num[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  if (n == 3 && num[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  cout << num << endl;
  return 0;
}
