#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s, c;
  vector<int> num(N);
  for (int(i) = 0; (i) < (N); (i)++) num[i] = -1;
  while (M) {
    cin >> s >> c;
    if (s == 1 && c == 0 && N != 1 || num[s - 1] != -1 && num[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    } else
      num[s - 1] = c;
    M--;
  }
  for (int(i) = 0; (i) < (N); (i)++) {
    if (num[i] == -1) {
      num[i] = 0;
    }
    cout << num[i];
  }
  cout << '\n';
}
