#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > v(m);
  for (long long i = 0; i < (long long)m; ++i) cin >> v[i].first >> v[i].second;
  sort(begin(v), end(v));
  v.resize(unique(begin(v), end(v)) - v.begin());
  for (long long i = 1; i <= (long long)(long long)v.size() - 1; ++i)
    if (v[i].first == v[i - 1].first) {
      cout << -1;
      return;
    };
  if (!v.empty() && v[0] == make_pair(1ll, 0ll) && n > 1) {
    cout << -1;
    return;
  };
  vector<long long> ans(n);
  for (pair<long long, long long> p : v) ans[p.first - 1] = p.second;
  if (!ans[0]) ans[0] = 1;
  for (long long x : ans) cout << x;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
