#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, dig[3] = {-1, -1, -1};
  cin >> N >> M;
  bool flag = true;
  for (int i = 0, s, c; i < M; i++) {
    cin >> s >> c;
    s--;
    if (dig[s] >= 0 || dig[s] != c)
      flag = false;
    else
      dig[s] = c;
  }
  if (flag && !(dig[0] == 0 && N > 1)) {
    for (int i = 0; i < N; i++) {
      if (dig[i] >= 0)
        cout << dig[i];
      else
        cout << (i > 0 ? 0 : 1);
    }
  } else
    cout << "-1" << endl;
  return 0;
}
