#include <bits/stdc++.h>
using namespace std;
int N, M;
int sv[10];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> N >> M;
  for (int i = 0; i < N; i++) sv[i] = -1;
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    if (sv[x] != -1 && sv[x] != y) {
      cout << "-1\n";
      return 0;
    }
    sv[x] = y;
  }
  if (sv[0] == 0 && N > 1) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 0; i < N; i++) cout << max(sv[i], 0);
  cout << "\n";
}
