#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < (m); ++i) cin >> s[i] >> c[i];
  int answer = -1;
  int first = 0;
  int end = 10;
  if (n == 2) {
    first = 10;
    end = 100;
  }
  if (n == 3) {
    first = 100;
    end = 1000;
  }
  for (int i = first; i < end; i++) {
    bool ok[m];
    int hikaku[n];
    int buf = i;
    for (int i = 0; i < (n); ++i) {
      hikaku[n - i - 1] = buf % 10;
      if (buf > 1) buf /= 10;
    }
    for (int j = 0; j < (m); ++j) {
      if (hikaku[s[j] - 1] == c[j]) {
        ok[j] = true;
      }
    }
    bool ans = true;
    for (int i = 0; i < (m); ++i)
      if (!ok[i]) ans = false;
    if (ans) {
      answer = i;
      break;
    }
  }
  cout << answer << endl;
  return 0;
}
