#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> p(M);
  map<int, int> mp;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (mp[s] != 0 && mp[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    mp[s] = c;
    p[i] = make_pair(s, c);
  }
  sort(p.begin(), p.end());
  if (p[0].second == 0) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> ans(N);
  for (int i = 1; i <= N; i++) {
    if (mp[i] != 0) {
      ans[i] = mp[i];
    } else {
      ans[i] = 0;
    }
  }
  for (int i = 1; i <= N; i++) {
    cout << ans[i];
  }
  return 0;
}
