#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(void) {
  int n, m;
  cin >> n >> m;
  int table[n][m];
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    table[i][0] = s;
    table[i][1] = c;
  }
  for (int num = pow(10, n - 1); num < pow(10, n); num++) {
    bool piv = true;
    if (n == 3) {
      for (int i = 0; i < m; i++) {
        int temp;
        if (table[i][0] == 1) {
          temp = num / 100;
        } else if (table[i][0] == 2) {
          temp = (num / 10) % 10;
        } else {
          temp = num % 10;
        }
        if (table[i][1] != temp) {
          piv = false;
        }
      }
    } else if (n == 2) {
      for (int i = 0; i < m; i++) {
        int temp;
        if (table[i][0] == 1) {
          temp = num / 10;
        } else {
          temp = num % 10;
        }
        if (table[i][1] != temp) {
          piv = false;
        }
      }
    } else {
      for (int i = 0; i < m; i++) {
        int temp;
        temp = num;
        if (table[i][1] != temp) {
          piv = false;
        }
      }
    }
    if (piv) {
      cout << num << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
