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