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