#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int num[n];
  int pos, dig;
  bool bad = false;
  memset(num, -1, sizeof num);
  for (int i = 0; i < m; i++) {
    cin >> pos >> dig;
    pos--;
    if (num[pos] != -1 and num[pos] != dig) {
      bad = true;
      break;
    } else
      (num[pos] = dig);
  }
  if (m == 0) {
    cout << 0;
    return 0;
  }
  if (num[0] == -1) num[0] = 1;
  if (num[0] == 0 and n > 1) bad = true;
  if (bad)
    cout << -1 << "\n";
  else {
    for (auto x : num) {
      if (x == -1)
        cout << 0;
      else
        cout << x;
    }
  }
}
