#include <bits/stdc++.h>
using namespace std;
map<int, int> marked;
vector<vector<int>> Sheet;
int main() {
  int n, m;
  string num;
  cin >> n >> m;
  num.resize(n, '0');
  int in1, in2;
  map<int, int> isIn;
  for (int i = 0; i < m; i++) {
    cin >> in1 >> in2;
    if (isIn[in1] && num[in1 - 1] != to_string(in2)[0]) {
      cout << -1;
      return 0;
    }
    num[in1 - 1] = to_string(in2)[0];
    isIn[in1] = true;
  }
  if (num.size() != 1) {
    for (int i = 0; i < num.size(); i++) {
      if (num[i] == '0') {
        cout << -1;
        return 0;
      } else {
        break;
      }
    }
  }
  cout << num;
}
