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