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