#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m), c(m);
  vector<long long> min(n, 10);
  string ans;
  vector<char> cs(n, '0');
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  if (n == 1) {
    int min = c[0];
    char ans;
    if (m > 0) {
      for (int i = 0; i < (m); i++) {
        if (c[i] < min) min = c[i];
      }
    } else
      min = 0;
    ans = min + '0';
    cout << ans << endl;
    return 0;
  }
  bool on = false;
  for (int i = 0; i < (m); i++) {
    if (s[i] == 0 && c[i] > 0) {
      on = true;
    }
  }
  if (!on) {
    ans = "-1";
    cout << ans << endl;
    return 0;
  }
  for (int i = 0; i < (m); i++) {
    if (min[s[i]] > c[i]) min[s[i]] = c[i];
  }
  for (int i = 0; i < (m); i++) {
    cs[s[i]] = min[s[i]] + '0';
  }
  for (char tmp : cs) ans.push_back(tmp);
  cout << ans << endl;
  return 0;
}
