#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  std::deque<int> deq(n, -1);
  int m, s, c, flag = 0;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (deq[s - 1] == -1 || deq[s - 1] == c) {
      deq[s - 1] = c;
      if (s - 1 != 0 && c != 0) {
        flag = 2;
      }
    } else {
      flag = 1;
      break;
    }
  }
  if (flag == 1) {
    cout << -1 << endl;
  } else if (flag == 2) {
    if (n == 1) {
      cout << deq[0] << endl;
    } else {
      for (int j = 0; j < n; j++) {
        if (j == 0 && deq[0] == -1) {
          cout << 1;
        } else if (deq[j] == -1) {
          cout << 0;
        } else {
          cout << deq[j];
        }
      }
      cout << endl;
    }
  } else {
    if (n == 1) {
      cout << deq[0] << endl;
    } else {
      if (deq[0] == 0) {
        cout << -1 << endl;
      } else {
        for (int k = 0; k < n; k++) {
          if (k == 0 && deq[k] == -1) {
            cout << 1;
          } else if (deq[k] == -1) {
            cout << 0;
          } else {
            cout << deq[k];
          }
        }
        cout << endl;
      }
    }
  }
}
