#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> digit(N, 1);
  vector<bool> decided(N, false);
  while (M--) {
    int s, c;
    cin >> s >> c;
    if (decided[s - 1] && digit[s - 1] != c) {
      cout << -1 << endl;
      goto FIN;
    }
    decided[s - 1] = true;
    digit[s - 1] = c;
  }
  if (N > 1 && digit[0] == 0) {
    cout << -1 << endl;
    goto FIN;
  }
  for (auto d : digit) cout << d;
  cout << endl;
FIN:;
  return 0;
}
