#include <bits/stdc++.h>
using namespace std;
struct Hey {
  int pos, val;
};
int main() {
  int digs = 0;
  int instr = 0;
  cin >> digs >> instr;
  int temp = 0;
  vector<bool> done(digs);
  vector<Hey> heys(instr);
  for (int j = 0; j < instr; ++j) {
    cin >> heys[j].pos >> heys[j].val;
    if (done[heys[j].pos] == true) {
      for (int k = 0; k < j + 1; ++k) {
        if (heys[j].pos == heys[k].pos) {
          if (heys[j].val != heys[k].val) {
            cout << -1 << endl;
            return 0;
          }
        }
      }
    }
    if (done[heys[j].pos] == false) {
      temp += pow(10, digs - heys[j].pos) * heys[j].val;
    }
    done[heys[j].pos] = true;
  }
  if (temp == 0)
    cout << -1 << endl;
  else
    cout << temp << endl;
}
