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