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