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