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