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