#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, M;
  cin >> N >> M;
  map<ll, ll> order;
  for (ll i = 0; i < M; i++) {
    ll c, s;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    } else if (order.find(s) == order.end()) {
      order[s] = c;
    } else {
      if (order[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  string ans;
  for (ll i = 1; i <= N; i++) {
    if (order.find(i) == order.end()) {
      if (i == 1 && N != 1)
        ans += '1';
      else
        ans += '0';
    } else {
      ans += to_string(order[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
