#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  int result_100 = 0, result_10 = 0, result_1 = 0;
  int ans;
  int count = 0;
  if (N == 3) {
    for (int i = 0; i < M; i++) {
      if (s[i] == 1 && c[i] != 0) {
        count += 1;
      }
    }
    if (count == 0) {
      ans = -1;
    } else {
      for (int i = 0; i < M; i++) {
        if (s[i] == 1) {
          result_100 = c[i];
        }
        if (s[i] == 2) {
          result_10 = c[i];
        }
        if (s[i] == 3) {
          result_1 = c[i];
        }
      }
      ans = result_100 * 100 + result_10 * 10 + result_1;
    }
  }
  if (N == 2) {
    for (int i = 0; i < M; i++) {
      if (s[i] == 2 && c[i] != 0) {
        count += 1;
      }
    }
    if (count == 0) {
      ans = -1;
    } else {
      for (int i = 0; i < M; i++) {
        if (s[i] == 2) {
          result_10 = c[i];
        }
        if (s[i] == 3) {
          result_1 = c[i];
        }
      }
      ans = result_10 * 10 + result_1;
    }
  }
  if (N == 1) {
    for (int i = 0; i < M; i++) {
      if (s[i] == 3 && c[i] != 0) {
        count += 1;
      }
    }
    if (count == 0) {
      ans = -1;
    } else {
      for (int i = 0; i < M; i++) {
        if (s[i] == 3) {
          result_1 = c[i];
        }
      }
      ans = result_1;
    }
  }
  cout << ans << endl;
}
