#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, c;
  cin >> n >> m;
  int arr[n];
  for (int i = 0; i < n; i++) arr[i] = -1;
  while (m--) {
    cin >> s >> c;
    if (arr[s - 1] == -1 || arr[s - 1] == c)
      arr[s - 1] = c;
    else {
      cout << "-1";
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] == -1) arr[i] = 0;
  }
  if (n > 1) {
    if (arr[0] == 0) {
      cout << "-1";
      return 0;
    }
  }
  for (int i = 0; i < n; i++) cout << arr[i];
}
