#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[100], c[100];
  for (int i = 1; i <= m; i++) {
    cin >> s[i] >> c[i];
  }
  if (s[1] == 0) {
    if (n != 1) {
      cout << "-1";
      return 0;
    } else {
      cout << "0";
      return 0;
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = i + 1; j <= m; j++) {
      if (s[i] == s[j] and c[i] != c[j]) {
        cout << "-1";
        return 0;
      }
    }
  }
  int r = 1;
  for (int i = 1; i <= m; i++) {
    if (s[i] == r) {
      cout << c[i];
      r++;
    } else {
      cout << "0";
    }
  }
  return 0;
}
