#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  int s[5], c[5];
  for (int i(0); i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int flag(true);
  for (int i(0); i < m; i++) {
    if (s[i] == 1 && c[i] == 0) {
      flag = false;
    }
  }
  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]) {
        flag = false;
      }
    }
  }
  if (flag) {
    int answer[5];
    bool joined[5];
    for (int i(0); i < m; i++) {
      answer[i] = 0;
      joined[i] = false;
    }
    for (int i(0); i < m; i++) {
      if (joined[i] == false) {
        answer[s[i] - 1] = c[i];
        joined[i] = true;
      } else if (joined[i] == true) {
        if (answer[s[i] - 1] > c[i]) {
          answer[s[i] - 1] = c[i];
        }
      }
    }
    for (int i(0); i < m; i++) {
      cout << answer[i];
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
