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