#include <bits/stdc++.h>
using namespace std;
int main() {
  int N = 0, M = 0, s[10][2];
  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) {
    int resultAA = s[1][1];
    cout << resultAA << endl;
    return 0;
  }
  if (N == 2) {
    if (s[1][1] != 0) {
      int resultAA = 10 * s[1][1] + 1 * s[2][1];
      cout << resultAA << endl;
      return 0;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (N == 3) {
    if (s[1][1] != 0 && s[2][1] != 0) {
      int resultAA = 100 * s[1][1] + 10 * s[2][1] + 1 * s[3][1];
      cout << resultAA << endl;
      return 0;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  return 0;
}
