#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  ll N, M;
  cin >> N >> M;
  string S = "";
  for (int i = 0; i < N; i++) S += "0";
  vector<bool> fixed(N);
  for (int i = 0; i < N; i++) fixed[i] = false;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (fixed[s] && S[s] != c + '0') {
      cout << -1 << endl;
      return 0;
    }
    S.replace(s, 1, to_string(c));
    fixed[s] = true;
  }
  if (fixed[0] && S[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  if (S[0] == '0' && S.size() > 1) S.replace(0, 1, to_string(1));
  cout << S << endl;
  return 0;
}
