#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int start = 1;
  int end = 10;
  for (int i = 1; i < n; i++) {
    start *= 10;
    end *= 10;
  }
  for (int i = start; i < end; i++) {
    bool flag = true;
    for (int j = 0; j < m; j++) {
      int digN = 0;
      if (n == 1) {
        digN = i;
      } else if (n == 2) {
        if (s[j] == 1) digN = i / 10;
        if (s[j] == 2) digN = i % 10;
      } else {
        if (s[j] == 1) digN = i / 100;
        if (s[j] == 2) digN = (i / 10) % 10;
        if (s[j] == 3) digN = i % 10;
      }
      if (digN != c[j]) {
        flag = false;
        continue;
      } else {
      }
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
