#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[5], c[5];
  int digit[3];
  bool digit_insert[3];
  for (int i = 0; i < 3; i++) {
    digit[i] = 0;
    digit_insert[i] = false;
  }
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  bool collision = false;
  for (int i = 0; i < m; i++) {
    if (digit[3 - s[i]] > 0) {
      if (digit[3 - s[i]] != c[i]) collision = true;
    }
    digit[3 - s[i]] = c[i];
    digit_insert[3 - s[i]] = true;
  }
  int number = 0;
  for (int i = 0; i < n; i++) {
    number += digit[i] * (int)pow(10, i);
  }
  bool wrong_number = false;
  if (digit_insert[2] == true && digit[2] == 0)
    wrong_number = true;
  else if (digit_insert[1] == true && digit[1] == 0)
    wrong_number = true;
  if (collision || wrong_number)
    cout << -1 << endl;
  else
    cout << number << endl;
}
