#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  string s;
  int tmp1, tmp2;
  vector<int> x, y;
  for (int i = 0; i < M; i++) {
    cin >> tmp1 >> tmp2;
    x.push_back(tmp1);
    y.push_back(tmp2);
  }
  for (int i = 0; i < 1000; i++) {
    s = to_string(i);
    for (int k = 0; k < M; k++) {
      if (s[x[k] - 1] - '0' == y[k]) {
        if ((N == 3 && s[0] != 0 && k == M - 1) || (N <= 2 && k == M - 1)) {
          cout << i << endl;
          return 0;
        }
      } else {
        break;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
