#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  int error = 0;
  int a100 = 0;
  int a10 = 0;
  int a1 = 0;
  int c100 = 0;
  int c10 = 0;
  int c1 = 0;
  if (N == 3) {
    for (int i = 0; i < M; i++) {
      if (s.at(i) > N) {
        error = 1;
        break;
      }
      if (s.at(i) == 1) {
        if (c.at(i) == 0) {
          error = 1;
        } else if (c100 == 0 || a100 == c.at(i)) {
          a100 = c.at(i);
          c100++;
        } else {
          error = 1;
        }
      }
      if (s.at(i) == 2) {
        if (c10 == 0 || a10 == c.at(i)) {
          a10 = c.at(i);
          c10++;
        } else {
          error = 1;
        }
      }
      if (s.at(i) == 3) {
        if (c1 == 0 || a1 == c.at(i)) {
          a1 = c.at(i);
          c1++;
        } else {
          error = 1;
        }
      }
    }
  }
  if (N == 2) {
    for (int i = 0; i < M; i++) {
      if (s.at(i) > N) {
        error = 1;
        break;
      }
      if (s.at(i) == 1) {
        if (c.at(i) == 0) {
          error = 1;
        } else if (c10 == 0 || a10 == c.at(i)) {
          a100 = c.at(i);
        } else {
          error = 1;
        }
      }
      if (s.at(i) == 3) {
        if (c1 == 0 || a1 == c.at(i)) {
          a1 = c.at(i);
        } else {
          error = 1;
        }
      }
    }
  }
  if (N == 1) {
    for (int i = 0; i < M; i++) {
      if (s.at(i) > N) {
        error = 1;
        break;
      }
      if (s.at(i) == 1) {
        if (c1 == 0 || a1 == c.at(i)) {
          a1 = c.at(i);
        } else {
          error = 1;
        }
      }
    }
  }
  if (error == 1) {
    cout << "-1" << endl;
  } else {
    if (N == 3 && a100 == 0) {
      a100 = 1;
    } else if (N == 2 && a10 == 0) {
      a10 = 1;
    }
    int ans = 100 * a100 + 10 * a10 + a1;
    cout << ans << endl;
  }
}
