#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  int s[7];
  int c[7];
  for (int i = 1; i <= M; i++) {
    cin >> s[i] >> c[i];
  }
  int min = 0;
  int ans[4] = {0};
  if (N == 2) ans[1] = 1;
  if (N == 3) ans[2] = 1;
  for (int i = 1; i <= M; i++) {
    if ((N == 3 || N == 2) && s[i] == 1 && c[i] == 0) {
      min = 1;
      break;
    }
    ans[N - s[i]] = c[i];
  }
  for (int i = 1; i <= N; i++) {
    int judge = 0;
    int tag = 10;
    for (int j = 1; j <= M; j++) {
      if (s[j] == i) tag = c[j];
      break;
    }
    if (tag != 10) {
      for (int j = 1; j <= M; j++) {
        if (s[j] == i && c[i] != tag) {
          judge = 1;
        }
      }
    }
    if (judge == 1) {
      cout << -1 << endl;
      min = 1;
    }
  }
  if (min == 1)
    cout << -1 << endl;
  else {
    int answer = ans[0] + ans[1] * 10 + ans[2] * 100;
    cout << answer << endl;
  }
  return 0;
}
