#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, si, ci;
  cin >> n >> m;
  int minsi = INT_MAX, s[n + 1];
  memset(s, -1, sizeof(s));
  bool isok = true;
  for (int i = 0; i < m; i++) {
    cin >> si >> ci;
    minsi = min(si, minsi);
    if (s[si] == -1)
      s[si] = ci;
    else {
      if (s[si] != ci) isok = false;
    }
  }
  if (s[1] != 0 && isok) {
    string result = "";
    if (minsi == 1)
      result += (48 + s[1]);
    else
      result += '1';
    for (int i = 2; i <= n; i++) {
      if (s[i] == -1)
        result += "0";
      else
        result += (48 + s[i]);
    }
    cout << result;
  } else {
    if (n == 1)
      cout << 0;
    else
      cout << -1;
  }
}
