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