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