#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> P(N);
  for (int i = 0; i < M; i++) {
    cin >> P[i].first >> P[i].second;
  }
  int n1 = -1;
  int n2 = -1;
  int n3 = -1;
  int r = -1;
  if (N == 3) {
    for (int i = 0; i < M; i++) {
      if (P[i].first == 1) {
        if (P[i].second == 0) {
          cout << r << endl;
          return 0;
        }
        if (n1 != -1 && n1 != P[i].second) {
          cout << r << endl;
          return 0;
        }
        n1 = P[i].second;
      }
      if (P[i].first == 2) {
        if (n2 != -1 && n2 != P[i].second) {
          cout << r << endl;
          return 0;
        }
        n2 = P[i].second;
      }
      if (P[i].first == 3) {
        if (n3 != -1 && n3 != P[i].second) {
          cout << r << endl;
          return 0;
        }
        n3 = P[i].second;
      }
    }
    if (n1 == 0) {
      cout << r << endl;
      return 0;
    }
    r = n1 * 100;
    if (n2 == -1) n2 = 0;
    r += n2 * 10;
    if (n3 == -1) n3 = 0;
    r += n3;
  } else if (N == 2) {
    for (int i = 0; i < M; i++) {
      if (P[i].first == 1) {
        if (P[i].second == 0) {
          cout << r << endl;
          return 0;
        }
        if (n1 != -1 && n1 != P[i].second) {
          cout << r << endl;
          return 0;
        }
        n1 = P[i].second;
      }
      if (P[i].first == 2) {
        if (n2 != -1 && n2 != P[i].second) {
          cout << r << endl;
          return 0;
        }
        n2 = P[i].second;
      }
      if (P[i].first == 3) {
        cout << r << endl;
        return 0;
      }
    }
    if (n1 == 0) {
      cout << r << endl;
      return 0;
    }
    r = n1 * 10;
    if (n2 == -1) n2 = 0;
    r += n2;
  } else {
    for (int i = 0; i < M; i++) {
      if (P[i].first == 1) {
        if (n1 != -1 && n1 != P[i].second) {
          cout << r << endl;
          return 0;
        }
        n1 = P[i].second;
      }
      if (P[i].first == 2) {
        cout << r << endl;
        return 0;
      }
      if (P[i].first == 3) {
        cout << r << endl;
        return 0;
      }
    }
    r = n1;
  }
  cout << r << endl;
}
