#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int f = 0;
  vector<int> num(n, 0);
  vector<int> check(n, 0);
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    if (c == 0 && s == 1 && n != 1) {
      f = 1;
      break;
    } else if (check[s - 1] != 0 && num[s - 1] != c) {
      f = 1;
      break;
    } else if (c != 0) {
      num[s - 1] = c;
      check[s - 1] = -1;
    }
  }
  if (f == 1)
    cout << -1 << endl;
  else {
    if (check[0] == 0) {
      num[0] = 1;
    }
    for (int i = 0; i < (int)(n); i++) cout << num[i];
  }
}
