#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> ar;
  int n, m;
  cin >> n >> m;
  int check = 0, check2 = 0;
  while (m--) {
    int in1, in2;
    cin >> in1 >> in2;
    if (ar[in1] > 0 && ar[in1] != in2) check = 1;
    if (ar[in1] != 0 && in2 == 0) check = 1;
    ar[in1] = in2;
  }
  if (ar[1] == 0 && n > 1) check = 1;
  if (check == 1)
    cout << "-1\n";
  else {
    for (int i = 1; i <= n; i++) {
      if (ar[i] >= 0)
        cout << ar[i];
      else
        cout << "0";
    }
    cout << endl;
  }
  return 0;
}
