#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  int ans = -1;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int min = 0;
  int max = 9;
  if (n == 2) {
    min = 10;
    max = 99;
  } else if (n = 3) {
    min = 100;
    max = 999;
  }
  vector<int> dig(3);
  int w = 0;
  int S;
  for (int i = min; i <= max; i++) {
    w = 0;
    for (int j = 0; j < m; j++) {
      if (n == 1) {
        dig[0] = i;
      } else if (n == 2) {
        dig[0] = i / 10;
        dig[1] = i % 10;
      } else {
        dig[0] = i / 100;
        dig[1] = (i / 10) % 10;
        dig[2] = i % 100;
      }
      if (dig[s[j] - 1] != c[j]) {
        w = 1;
        break;
      }
    }
    if (w == 0) {
      ans = i;
      break;
    }
  }
  cout << ans;
}
