#include <bits/stdc++.h>
using namespace std;
using int64 = long long int;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> digit(n, -1);
  for (int _ = 0; _ < m; _++) {
    int s, c;
    cin >> s >> c;
    s--;
    if ((digit[s] != -1 && digit[s] != c) || (s == 0 && c == 0)) {
      cout << -1 << endl;
      return 0;
    }
    digit[s] = c;
  }
  for (size_t i = 0; i < digit.size(); i++) {
    int value = i == 0 ? 1 : 0;
    value = max(value, digit[i]);
    cout << value;
  }
  cout << endl;
}
