#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int m;
  cin >> n >> m;
  vector<int> c(3, -1);
  int flag = 0;
  int tmps;
  int tmpc;
  for (int i = 0; i < m; i++) {
    cin >> tmps;
    if (c.at(tmps - 1) < 0) {
      cin >> c.at(tmps - 1);
    } else {
      cin >> tmpc;
      if (n != 1 && (c.at(tmps - 1) != tmpc)) {
        flag = 1;
      }
    }
  }
  if (n == 1 && c.at(0) == 0) {
  } else if (c.at(0) == -1 || c.at(0) == 0) {
    flag = 1;
  }
  for (int i = 0; i < n; i++) {
    if (c.at(i) == -1) {
      c.at(i) = 0;
    }
  }
  if (flag == 0) {
    for (int i = 0; i < n; i++) {
      cout << c.at(i);
    }
  } else {
    cout << -1 << endl;
  }
}
