#include <bits/stdc++.h>
using namespace std;
int main() {
  int number[3];
  number[0] = number[1] = number[2] = -1;
  int n, m, s, c;
  cin >> n >> m;
  bool isValid = true;
  for (int i = 0; i < m; ++i) {
    cin >> s >> c;
    if (number[s - 1] != -1 && number[s - 1] != c) {
      isValid = false;
      break;
    }
    number[s - 1] = c;
  }
  if (!isValid || (number[0] == 0 && n > 1))
    cout << "-1" << endl;
  else {
    if (number[0] == -1) number[0] = 1;
    for (int i = 0; i < n; ++i) {
      cout << (number[i] == -1 ? 0 : number[i]);
    }
    cout << endl;
  }
  return 0;
}
