#include <bits/stdc++.h>
using namespace std;
int arr[10];
bool f;
int main() {
  int n, m;
  cin >> n >> m;
  memset(arr, -1, sizeof arr);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 1 && b == 0) {
      cout << -1;
      return 0;
    }
    if (arr[a] == b || arr[a] == -1) {
      arr[a] = b;
      continue;
    }
    cout << -1;
    return 0;
  }
  int s, e;
  if (n == 1)
    s = 1, e = 9;
  else if (n == 2)
    s = 10, e = 99;
  else if (n == 3)
    s = 100, e = 999;
  for (int i = s; i <= e; i++) {
    if (n == 1) {
      if (arr[1] == i || arr[1] == -1) {
        cout << i;
        return 0;
      }
    }
    if (n == 2) {
      if ((arr[1] == i / 10 || arr[1] == -1) &&
          (arr[2] == i % 10 || arr[2] == -1)) {
        cout << i;
        return 0;
      }
    }
    if (n == 3) {
      if ((arr[1] == i / 100 || arr[1] == -1) &&
          (arr[2] == i / 10 % 10 || arr[2] == -1) &&
          (arr[3] == i % 10 || arr[3] == -1)) {
        cout << i;
        return 0;
      }
    }
  }
  cout << -1;
}
