#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int sc[m][2];
  for (int i = 0; i < m; i++) {
    cin >> sc[i][0];
    cin >> sc[i][1];
  }
  bool flag = true;
  int list[3] = {10, 10, 10};
  for (int i = 0; i < m; i++) {
    if (sc[i][0] == 1 && sc[i][1] == 0)
      flag = false;
    else {
      if (sc[i][1] == list[sc[i][0] - 1] || list[sc[i][0] - 1] == 10) {
        list[sc[i][0] - 1] = sc[i][1];
      } else
        flag = false;
    }
  }
  if (!flag)
    cout << -1 << endl;
  else if (n == 1 && list[0] == 10)
    cout << 0 << endl;
  else {
    for (int i = 0; i < n; i++) {
      if (list[i] == 10 && i == 0)
        cout << 1;
      else if (list[i] == 10)
        cout << 0;
      else
        cout << list[i];
    }
    cout << endl;
  }
}
