#include <bits/stdc++.h>
using namespace std;
int N;
int M;
int s[10];
int c[10];
int main() {
  cin >> N;
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  for (int i = 0; i < M; i++) {
    if (s[i] == 1 && c[i] == 0) {
      cout << "-1" << endl;
      exit(0);
    }
  }
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if (s[i] == s[j] && i != j) {
        if (c[i] != c[j]) {
          cout << "-1" << endl;
          exit(0);
        } else {
          s[j] = 0;
        }
      }
    }
  }
  int number;
  for (int i = 0; i < M; i++) {
    if (s[i] == 0) continue;
    number += c[i] * pow(10, N - s[i]);
    if (pow(10, N - 1) > number) {
      number += pow(10, N - 1);
    }
  }
  cout << number << endl;
}
