#include <bits/stdc++.h>
using namespace std;
int s[6];
int c[10];
int main(void) {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  int ans = -1;
  int c1 = 10;
  int c2 = 10;
  int c3 = 10;
  for (int i = 0; i < M; i++) {
    if (s[i] == 1)
      if (c1 != 10) {
        cout << -1 << endl;
        return 0;
      } else {
        c1 = c[i];
      }
  }
  for (int i = 0; i < M; i++) {
    if (s[i] == 2)
      if (c2 != 10) {
        cout << -1 << endl;
        return 0;
      } else {
        c2 = c[i];
      }
  }
  for (int i = 0; i < M; i++) {
    if (s[i] == 3)
      if (c3 != 10) {
        cout << -1 << endl;
        return 0;
      } else {
        c3 = c[i];
      }
  }
  if (N == 3) {
    if (c1 == 0) {
      cout << -1 << endl;
    } else {
      if (c1 > 9) {
        c1 = 1;
      }
      if (c2 > 9) {
        c2 = 0;
      }
      if (c3 > 9) {
        c3 = 0;
      }
      cout << c1 << c2 << c3 << endl;
    }
  }
  if (N == 2) {
    if (c1 == 0) {
      cout << -1 << endl;
    } else {
      if (c1 > 9) {
        c1 = 1;
      }
      if (c2 > 9) {
        c2 = 0;
      }
      cout << c1 << c2 << endl;
    }
  }
  if (N == 1) {
    if (c1 > 9) {
      cout << 0 << endl;
    } else {
      cout << c1 << endl;
    }
  }
  return 0;
}
