#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  int dig[3] = {0, 0, 0};
  int s, c;
  for (int i = 0; i < m; ++i) {
    cin >> s >> c;
    s--;
    if (s == 0 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (s > 0 && dig[s] != 0 && c != dig[s]) {
      cout << -1 << endl;
      return 0;
    }
    dig[s] = c;
  }
  cout << dig[0] * 100 + dig[1] * 10 + dig[2] << endl;
  return 0;
}
