#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int c[M], s[M];
  for (int i = 0; i < M; i++) {
    cin >> c[i] >> s[i];
  }
  int res = -1;
  if (N == 1) {
    bool ok = true;
    for (int n = 9; n >= 0; n--) {
      for (int i = 0; i < M; i++) {
        if (c[i] != 1 || s[i] != n) {
          ok = false;
        }
      }
      if (ok) {
        res = n;
      }
    }
  } else if (N == 2) {
    bool ok = true;
    for (int n = 99; n >= 10; n--) {
      int n1 = n / 10;
      int n2 = n % 10;
      for (int i = 0; i < M; i++) {
        if (c[i] == 1) {
          if (s[i] != n1) {
            ok = false;
          }
        }
        if (c[i] == 2) {
          if (s[i] != n2) {
            ok = false;
          }
        }
      }
      if (ok) {
        res = n;
      }
    }
  } else if (N == 3) {
    for (int n = 999; n >= 100; n--) {
      bool ok = true;
      int n1 = n / 100;
      int m1 = n % 100;
      int n2 = m1 / 10;
      int n3 = m1 % 10;
      for (int i = 0; i < M; i++) {
        if (c[i] == 1) {
          if (s[i] != n1) {
            ok = false;
          }
        }
        if (c[i] == 2) {
          if (s[i] != n2) {
            ok = false;
          }
        }
        if (c[i] == 3) {
          if (s[i] != n3) {
            ok = false;
          }
        }
      }
      if (ok) {
        res = n;
      }
    }
  }
  cout << res << endl;
}
