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