#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, si, ci, i;
  cin >> n >> m;
  long long int arr[n], hash[n];
  for (i = 0; i < n; i++) {
    arr[i] = 0;
    hash[i] = 0;
  }
  if (n != 1) arr[0] = 1;
  bool flag = true;
  for (i = 0; i < m; i++) {
    cin >> si >> ci;
    si = si - 1;
    if (si >= n || si < 0) {
      flag = false;
    } else if (hash[si] == 1 and arr[si] != ci) {
      flag = false;
    } else {
      hash[si] = 1;
      arr[si] = ci;
    }
  }
  if (n == 1) {
    cout << arr[0];
  } else if (flag and arr[0] != 0) {
    for (i = 0; i < n; i++) {
      cout << arr[i];
    }
  } else {
    cout << -1;
  }
  return 0;
}
