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