#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int array[3]{-1, -1, -1};
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if ((a == 1 && b == 0 && n != 1) ||
        (array[a - 1] != -1 && array[a - 1] != b)) {
      cout << -1;
      return 0;
    }
    array[a - 1] = b;
  }
  if (array[0] == -1) {
    if (n != 1)
      array[0] = 1;
    else
      array[0] = 0;
  }
  if (array[1] == -1) array[1] = 0;
  if (array[2] == -1) array[2] = 0;
  cout << array[0] * 100 + array[1] * 10 + array[2];
}
