#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int M;
  int S[6];
  int C[6];
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> S[i] >> C[i];
  }
  int res = 0;
  bool flag = true;
  int arr[3];
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if (S[i] == S[j] && i != j) {
        if (C[i] != C[j]) {
          flag = false;
          break;
        }
      }
      arr[S[i] - 1] = C[i];
    }
  }
  if (flag && arr[0] != 0) {
    res = arr[0] * pow(10, 2) + arr[1] * pow(10, 1) + arr[2];
    cout << res << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
