#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 (cond.find(tmps) == cond.end())
      cond[tmps] = tmpc;
    else {
      if (cond[tmps] != tmpc) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  num = 0;
  index = 0;
  for (i = n; i > 0; i--) {
    num += cond[i] * pow(10, index++);
  }
  cout << num << endl;
  return 0;
}
