#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  for (int i = 0; i < n; i++) {
    a[i] = 0;
  }
  bool te = true;
  int s, c;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (s == 1 && c == 0) {
      te = false;
    }
    if (a[s - 1] == 0) {
      a[s - 1] = c;
    } else if (a[s - 1] == c) {
    } else {
      te = false;
    }
  }
  if (a[0] == 0) {
    a[0] = 1;
  }
  if (te) {
    for (int i = 0; i < n; i++) {
      cout << a[i];
    }
    cout << endl;
  } else {
    cout << "-1" << endl;
  }
}
