#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  int n, m, i, j, num, index;
  int tmps, tmpc;
  map<int, int> cond;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> tmps >> tmpc;
    if (n > 1 && tmps == 1 && tmpc == 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (cond.find(tmps) == cond.end())
      cond[tmps] = tmpc;
    else {
      if (cond[tmps] != tmpc) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  num = 0;
  index = 0;
  if (n == 1) num = cond[1];
  if (n == 2) num += cond[2] + cond[1] * 10;
  if (n == 3) num += cond[3] + cond[2] * 10 + cond[1] * 100;
  cout << num << endl;
  return 0;
}
