#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n == 0) {
    cout << 0;
    return 0;
  }
  int num[n];
  num[0] = 1;
  for (int i = 1; i < n; i++) {
    num[i] = 0;
  }
  int m;
  cin >> m;
  if (m == 0 && n == 1) {
    cout << 0;
    return 0;
  }
  if (n == 1) {
    int d, c;
    cin >> d, c;
    num[d - 1] = c;
    for (int i = 1; i < m; i++) {
      cin >> d >> c;
      if (num[0] != c) {
        cout << -1;
        return 0;
      }
    }
    cout << num[0];
    return 0;
  } else {
    for (int i = 0; i < m; i++) {
      int d, c;
      cin >> d >> c;
      if (num[d - 1] != c && num[d - 1] != 0 && 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;
}
