#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  vector<int> s1(m), c(m);
  for (int i = 0; i < m; i++) cin >> s1[i] >> c[i];
  if (m < n)
    cout << -1 << endl;
  else {
    string s;
    if (n == 0) n = 1;
    for (int i = 0; i < n; i++) s += '0';
    for (int i = 0; i < m; i++) {
      if (s[s1[i] - 1] != '0') {
        if (s[s1[i] - 1] - '0' > c[i]) s[s1[i] - 1] = (char)c[i] + '0';
      } else
        s[s1[i] - 1] = (char)c[i] + '0';
    }
    string s11;
    for (int i = 0; i < n; i++)
      if (s[i] != '0') {
        for (int j = i; j < n; j++) s11.push_back(s[j]);
        break;
      }
    cout << s11 << endl;
  }
}
