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