#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  int s, c;
  cin >> N;
  cin >> M;
  int a[3];
  for (int i = 0; i < 2; i++) {
    a[i] = -1;
  }
  if (N == 1) {
    for (int i = 1; i <= M; i++) {
      cin >> s;
      cin >> c;
      if (a[N - s] = -1) {
        a[N - s] = c;
      }
      if (a[N - s] != -1 && a[N - s] != c) {
        cout << "-1" << endl;
        return 0;
      }
      a[N - s] = c;
    }
    cout << a[0] << endl;
  }
  if (N == 2) {
    for (int i = 1; i <= M; i++) {
      cin >> s;
      cin >> c;
      if (a[N - s] = -1) {
        a[N - s] = c;
      }
      if (a[N - s] != -1 && a[N - s] != c) {
        cout << "-1" << endl;
        return 0;
      }
      a[N - s] = c;
    }
    if (a[1] == 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (a[1] == -1) {
      a[1] = 1;
    }
    cout << a[1] * 10 + a[0] << endl;
  }
  if (N = 3) {
    for (int i = 1; i <= M; i++) {
      cin >> s;
      cin >> c;
      if (a[N - s] = -1) {
        a[N - s] = c;
      }
      if (a[N - s] != -1 && a[N - s] != c) {
        cout << "-1" << endl;
        return 0;
      }
      a[N - s] = c;
    }
    if (a[2] == 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (a[2] == -1 && a[2] == 0) {
      a[2] = 1;
    }
    if (a[1] == -1) {
      a[1] = 0;
    }
    cout << a[2] * 100 + a[1] * 10 + a[0] << endl;
  }
  return 0;
}
