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