#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int num[n];
  for (int i = 0; i < n; i++) {
    num[i] = 0;
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int d, c;
    cin >> d >> c;
    if (num[d - 1] != c && num[d - 1] != 0) {
      cout << "-1";
      return 0;
    }
    num[d - 1] = c;
  }
  int orig = 0;
  for (int i = 0; i < n; i++) {
    orig = orig * 10 + num[i];
  }
  int dup = orig;
  int digit = 0;
  while (dup != 0) {
    dup = dup / 10;
    digit++;
  }
  if (digit == n) {
    cout << orig;
  } else {
    cout << -1;
  }
  return 0;
}
