#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> num(N);
  for (int i = 0; i < N; i++) {
    num[i] = 10;
  }
  int ans = 0;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (num[s - 1] == 10)
      num[s - 1] = c;
    else if (num[s - 1] == c)
      num[s - 1] = c;
    else {
      ans = -1;
      break;
    }
  }
  if (num[0] == 0) ans = -1;
  if (M == 0 && N == 3) ans = -1;
  if (N == 1 && num[0] == 0)
    cout << 0 << endl;
  else if (ans == -1)
    cout << ans << endl;
  else {
    for (int i = 0; i < N; i++) {
      if (num[i] == 10 && i == 0)
        num[i] = 1;
      else if (num[i] == 10)
        num[i] = 0;
      cout << num[i];
    }
    cout << endl;
  }
}
