#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans = 1;
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; ++i) cin >> s.at(i) >> c.at(i);
  vector<int> num(N, 0);
  vector<int> flg(N, 0);
  for (int i = 0; i < M; ++i) {
    if (flg.at(s.at(i) - 1) == 0) {
      num.at(s.at(i) - 1) = c.at(i);
      flg.at(s.at(i) - 1) = 1;
    } else if (num.at(s.at(i) - 1) != c.at(i)) {
      ans = -1;
      break;
    }
  }
  if (ans == -1)
    cout << ans << endl;
  else if (N > 1 && num.at(0) == 0) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < N; ++i) cout << num.at(i);
    cout << endl;
  }
}
