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