#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M];
  int c[M];
  for (int i = 0; i < M; ++i) {
    cin >> s[i] >> c[i];
  }
  if (N == 1) {
    int counter = 0;
    int answer = -1;
    if (M == 0) {
      cout << 0 << endl;
      return 0;
    }
    for (int i = 0; i < M; ++i) {
      if (s[i] == 1 && counter == 0) {
        answer = c[i];
        ++counter;
      }
    }
    cout << answer << endl;
    return 0;
  } else {
    int answer[N];
    int checker[N];
    for (int i = 0; i < N; ++i) {
      answer[i] = 0;
      checker[i] = 0;
    }
    answer[0] = 1;
    for (int i = 0; i < M; ++i) {
      int index = s[i] - 1;
      if (s[i] == 1 && c[i] == 0) {
        cout << -1 << endl;
        return 0;
      }
      if (checker[index] == 0 || checker[index] == c[i]) {
        answer[index] = c[i];
        checker[index] = c[i];
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
    for (int i = 0; i < N; ++i) {
      cout << answer[i];
    }
    cout << endl;
    return 0;
  }
}
