#include <bits/stdc++.h>
using namespace std;
map<int, int> m;
int N, M, s, c, result;
int main() {
  cin >> N >> M;
  result = 1;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (m.find(s) != m.end()) {
      if (m[s] != c) {
        result = 0;
        break;
      }
    } else {
      if (N > 1 && s == 1 && c == 0) {
        result = 0;
        break;
      } else {
        m[s] = c;
      }
    }
  }
  if (m.find(1) == m.end()) {
    m[1] = 1;
  }
  if (result) {
    for (int i = 1; i <= N; i++) {
      cout << m[i];
    }
  } else {
    cout << -1;
  }
  cout << endl;
  return 0;
}
