#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;
  int a, b;
  int check = 0;
  while (m--) {
    cin >> a >> b;
    if (arr[a - 1] == -1 || arr[a - 1] == b)
      arr[a - 1] = b;
    else
      check = 1;
  }
  if (n > 1 && check == 0) {
    check = 1;
    for (int i = 0; i < n; i++)
      if (arr[i] > 0) check = 0;
  }
  if (check == 1) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] == -1)
      cout << "0";
    else
      cout << arr[i];
  }
  cout << endl;
  return 0;
}
