#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0, m = 0, a = 0, b = 0, x = 0;
  cin >> n >> m;
  int array[n];
  for (int i = 0; i < n; i++) {
    array[i] = 10;
  }
  vector<pair<int, int>> cor;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    cor.push_back(make_pair(a, b));
  }
  for (int i = 0; i < cor.size(); i++) {
    if (array[cor[i].first - 1] == 10 ||
        array[cor[i].first - 1] == cor[i].second) {
      array[cor[i].first - 1] = cor[i].second;
    } else {
      cout << -1;
      return 0;
    }
  }
  if (array[0] == 0) {
    cout << -1;
    return 0;
  } else {
    if (array[0] == 10) {
      cout << 1;
      x = 1;
    }
    for (int i = x; i < n; i++) {
      if (array[i] == 10) {
        cout << 0;
      } else {
        cout << array[i];
      }
    }
  }
  return 0;
}
