#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int dig[n];
  for (int i = 0; i < m; i++) dig[i] = -1;
  int dum1, dum2;
  bool exist = true;
  for (int i = 0; i < m; i++) {
    cin >> dum1;
    cin >> dum2;
    if (dig[dum1 - 1] != -1 && dum2 != dig[dum1 - 1]) exist = false;
    dig[dum1 - 1] = dum2;
  }
  if (dig[0] == 0 || !exist) {
    cout << -1 << endl;
    return 0;
  }
  if (dig[0] == -1)
    cout << 1;
  else
    cout << dig[0];
  for (int i = 1; i < n; i++) {
    if (dig[i] == -1)
      cout << 0;
    else
      cout << dig[i];
  }
  cout << endl;
  return 0;
}
