#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
  int N, M;
  int s[M], c[M];
  cin >> N >> M;
  for (int i = 0; i < (int)(M); i++) cin >> s[i] >> c[i];
  vector<bool> can(1000, true);
  if (N == 1) {
    for (int i = 0; i <= 9; i++) {
      for (int j = 0; j < M; j++) {
        if (i != c[j]) can[i] = false;
      }
    }
  }
  if (N == 2) {
    for (int i = 0; i <= 9; i++) {
      can[i] = false;
    }
    for (int i = 10; i <= 99; i++) {
      for (int j = 0; j < M; j++) {
        if (s[j] == 1) {
          int a = i / 10;
          if (a != c[j]) can[i] = false;
        }
        if (s[j] == 2) {
          int a = i % 10;
          if (a != c[j]) can[i] = false;
        }
      }
    }
  }
  if (N == 3) {
    for (int i = 0; i <= 99; i++) {
      can[i] = false;
    }
    for (int i = 100; i <= 999; i++) {
      for (int j = 0; j < M; j++) {
        if (s[j] == 1) {
          int a = i / 100;
          if (a != c[j]) can[i] = false;
        }
        if (s[j] == 2) {
          int a = i % 100 / 10;
          if (a != c[j]) can[i] = false;
        }
        if (s[j] == 3) {
          int a = i % 10;
          if (a != c[j]) can[i] = false;
        }
      }
    }
  }
  bool flag = false;
  for (int i = 0; i < 1000; i++) {
    if (can[i]) {
      flag = true;
      cout << i << endl;
      break;
    }
  }
  if (!flag) cout << -1 << endl;
}
