#include <bits/stdc++.h>
using namespace std;
int main() {
  int N = 0, M = 0, s[10][2], A100 = 0, A10 = 0, A1 = 0;
  cin >> N >> M;
  for (int i = 0; i < 10; i++) {
    s[i][0] = 0;
    s[i][1] = 0;
  }
  for (int i = 1; i < M + 1; i++) {
    cin >> s[i][0] >> s[i][1];
  }
  bool result = false;
  if (N == 1) {
    for (int i = 1; i < M + 1; i++) {
      if (s[i][0] == 1) {
        A1 = s[1][1];
      }
    }
    int resultAA = 1 * A1;
    cout << resultAA << endl;
    return 0;
  }
  if (N == 2) {
    for (int i = 1; i < M + 1; i++) {
      if (s[i][0] == 1) {
        A10 = s[i][1];
      }
      if (s[i][0] == 2) {
        A1 = s[i][1];
      }
    }
    if (A10 != 0) {
      int resultAA = 10 * A10 + 1 * A1;
      cout << resultAA << endl;
      return 0;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (N == 3) {
    for (int i = 1; i < M + 1; i++) {
      if (s[i][0] == 1) {
        A100 = s[i][1];
      }
      if (s[i][0] == 2) {
        A10 = s[i][1];
      }
      if (s[i][0] == 3) {
        A1 = s[i][1];
      }
    }
    if (A100 != 0 && A10 != 0) {
      int resultAA = 100 * A100 + 10 * A10 + 1 * A1;
      cout << resultAA << endl;
      return 0;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  return 0;
}
