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