#include <bits/stdc++.h>
using namespace std;
int number_min(int digit, int max, int s[], int c[]) {
  double sum = 0;
  int digit_max = -1;
  if (max == 0) {
    return sum += pow(10, digit - 1);
  }
  for (int j = 0; j < max; j++) {
    if (digit > 1 && s[j] == 1 && c[j] == 0) {
      return -1;
    } else if (s[j] == 1) {
      digit_max = 0;
    }
  }
  for (int i = 1; i <= digit; i++) {
    for (int j = 0; j < max; j++) {
      if (s[j] == i) {
        sum += c[j] * pow(10, digit - i);
        for (int k = j + 1; k < max; k++) {
          if (s[k] == i && c[k] != c[j]) {
            return -1;
          }
        }
        break;
      }
    }
  }
  if (digit_max == -1) {
    sum += pow(10, digit - 1);
  }
  return sum;
}
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;
}
