#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  string num(M, '.');
  for (int i = 0; i < M; i++) {
    int c, s;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      if (N == 1) {
        cout << 0 << endl;
        return 0;
      } else {
        cout << -1 << endl;
        return 0;
      }
    } else if (num[s - 1] != '.' && num[s - 1] != c + '0') {
      cout << -1 << endl;
      return 0;
    }
    num[s - 1] = (char)(c + '0');
  }
  if (num[0] == '0') {
    num[0] = '1';
  }
  for (char &ch : num) {
    if (ch == '.') {
      ch = '0';
    }
  }
  int min_num = stoi(num);
  cout << min_num << endl;
  return 0;
}
