#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int c[n], s, ct;
  bool f = true;
  if (n == 1) {
    c[0] = 0;
    for (int i = 0; i < m; i++) {
      cin >> s >> ct;
      if (c[0] == 0 || c[0] == ct)
        c[0] = ct;
      else
        f = false;
    }
  } else {
    c[0] = 1;
    for (int i = 0; i < n - 1; i++) c[i + 1] = 0;
    for (int i = 0; i < m; i++) {
      cin >> s >> ct;
      if (s == 1) {
        if (ct == 0)
          f = false;
        else if (c[s - 1] == 0 || c[s - 1] == ct)
          c[s - 1] = ct;
        else
          f = false;
      } else {
        if (c[s - 1] == 0 || c[s - 1] == ct)
          c[s - 1] = ct;
        else
          break;
      }
    }
  }
  if (f)
    for (int i = 0; i < n; i++) cout << c[i];
  else
    cout << -1;
  return 0;
}
