#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int num[N];
  bool exist = true, zero = false;
  for (int i = 0; i < N; i++) num[i] = -1;
  int s[M], c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    if (num[s[i] - 1] == -1 || num[s[i] - 1] == c[i]) {
      num[s[i] - 1] = c[i];
    } else {
      exist = false;
    }
  }
  if (exist) {
    for (int i = 0; i < N; i++) {
      if (zero) {
        if (num[i] == -1) {
          cout << 0;
        } else {
          cout << num[i];
        }
      } else {
        if (num[i] == -1 || num[i] == 0) {
          if (i == N - 1) {
            cout << (-1);
          } else {
            continue;
          }
        } else {
          zero = true;
          cout << num[i];
        }
      }
    }
    cout << endl;
  } else {
    cout << (-1) << endl;
  }
  return 0;
}
