#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<pair<int, int> > regras;
  while (m--) {
    int s, c;
    cin >> s >> c;
    regras.push_back({s, c});
    a[s - 1] = c;
  }
  for (auto &p : regras) {
    if (a[p.first - 1] != p.second) {
      cout << -1 << '\n';
      return;
    }
  }
  if (a[0] == 0 and n != 1) {
    cout << -1 << '\n';
    return;
  }
  for (auto &v : a) cout << v;
  cout << '\n';
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  t = 1;
  while (t--) solve();
}
