#include <bits/stdc++.h>
using namespace std;
int number_min(int digit, int max, int s[], int c[]) {
  double sum = 0;
  bool check = false;
  int digit_max = -1;
  for (int i = 1; i <= digit; i++) {
    for (int j = 0; j < max; j++) {
      if (s[j] == 1) {
        digit_max = 0;
        if (c[j] == 0) {
          check = false;
        }
      }
      if (s[j] == i) {
        sum += c[j] * pow(10, digit - i);
        check = true;
        for (int k = j + 1; k < max; k++) {
          if (s[k] == i && c[k] != c[j]) {
            check = false;
          }
        }
        break;
      }
    }
  }
  if (digit_max == -1) {
    sum += pow(10, digit - 1);
  }
  return check ? sum : -1;
}
int main() {
  int digit;
  int max;
  cin >> digit >> max;
  int s[max], c[max];
  for (int i = 0; i < max; i++) {
    cin >> s[i] >> c[i];
  }
  cout << number_min(digit, max, s, c) << endl;
  return 0;
}
