#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1e9 + 7;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> ans(N, -1);
  for (int i = 0; i < M; ++i) {
    int S, C;
    cin >> S >> C;
    if (ans[S - 1] == -1 || ans[S - 1] == C) {
      ans[S - 1] = C;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (N == 1 && ans[2] == -1) {
    cout << 0 << endl;
    return 0;
  }
  if (N == 3 && ans[0] == -1) ans[0] = 1;
  if (N == 2 && ans[1] == -1) ans[1] = 1;
  if (N == 3) {
    for (int i = 0; i < N; ++i) {
      if (ans[i] == -1) ans[i] = 0;
      cout << ans[i];
    }
    cout << endl;
  }
  if (N == 2) {
    for (int i = 0; i < 2; ++i) {
      if (ans[i] == -1) ans[i] = 0;
      cout << ans[i];
    }
    cout << endl;
  }
  if (N == 1) {
    for (int i = 0; i < 1; ++i) {
      if (ans[i] == -1) ans[i] = 0;
      cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}
