#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  int start, end;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  if (n == 1) {
    start = 0;
    end = 9;
  } else if (n == 2) {
    start = 0;
    end = 99;
  } else if (n == 3) {
    start = 0;
    end = 999;
  } else {
    cout << -1;
    return 0;
  }
  for (int i = start; i <= end; i++) {
    int temp = i, digit;
    int flag = 1;
    for (int j = 0; j < m; j++) {
      temp = i;
      int digit_number = n - s[j] + 1;
      int digit_value = c[j];
      if (digit_number == 1) {
        if (temp % 10 != digit_value) {
          flag = 0;
          break;
        }
      } else {
        digit = (i / pow(10, n - 1));
        digit = digit % 10;
        if (digit != digit_value) {
          flag = 0;
          break;
        }
      }
    }
    if (flag) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
