#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
int main() {
  int N, M;
  cin >> N >> M;
  int i;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) cin >> s.at(i) >> c.at(i);
  vector<int> dig(N, -1);
  for (int i = 0; i < M; i++) {
    if (dig.at(s.at(i) - 1) == -1 || dig.at(s.at(i) - 1) == c.at(i)) {
      dig.at(s.at(i) - 1) = c.at(i);
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (dig.at(0) == -1 || (N > 1 && dig.at(0) == 0)) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    dig.at(i) = max(dig.at(i), 0);
  }
  for (int i = 0; i < N; i++) cout << dig.at(i);
  cout << endl;
  return 0;
}
