#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long N, M;
  cin >> N >> M;
  vector<long long> s(M);
  vector<long long> c(M);
  vector<long long> ans(N, 0);
  map<long long, long long> mm;
  for (long long i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  for (long long i = 0; i < M; i++) {
    if (mm[s.at(i)] != (long long)NULL) {
      if (mm[s.at(i)] != c.at(i)) {
        cout << "-1" << endl;
        return;
      }
      continue;
    }
    ans.at(s.at(i) - 1) = c.at(i);
    mm[s.at(i)] = c.at(i);
  }
  if (ans.at(0) == 0 && N != 1) {
    cout << "-1" << endl;
    return;
  }
  for (long long i = 0; i < N; i++) {
    cout << ans.at(i);
  }
  cout << endl;
  return;
}
int main() {
  solve();
  return 0;
}
