#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> tmp(n, 0);
  vector<int> memo(n, -1);
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    if (memo[s - 1] != -1 && memo[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    } else if (s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    memo[s - 1] = c;
    tmp[s - 1] = c;
  }
  for (int i = 0; i < m; ++i) {
    cout << tmp[i];
  }
  cout << endl;
}
