#include <bits/stdc++.h>
using namespace std;
int calcKeta(int val) {
  if (val == 0) {
    return 1;
  }
  int ret = 1;
  while (true) {
    if (val / 10 > 0) {
      ret++;
      val /= 10;
    } else {
      break;
    }
  }
  return ret;
}
int main() {
  int N;
  int M;
  cin >> N >> M;
  int s[M];
  int c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  bool isKetaAri = false;
  for (int i = 0; i < M; i++) {
    if (s[i] == N && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (s[i] == N) {
      isKetaAri = true;
    }
  }
  if (!isKetaAri) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < M; i++) {
    for (int j = i + 1; j < M; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int answer[3];
  for (int j = 1; j < N; j++) {
    for (int i = 0; i < M; i++) {
      if (s[i] == j) {
        answer[j - 1] = c[i];
      }
    }
  }
  cout << answer[0] * 100 + answer[1] * 10 + answer[2] << endl;
  return 0;
}
