#include <bits/stdc++.h>
using namespace std;
int min(int a[], int N, int b[]);
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  int a[n];
  int tmp[n];
  int lin;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < (int)(n); i++) {
    tmp[i] = 0;
  }
  if (n < 2) {
    int qt = min(c, m, s);
    if (qt < 10)
      cout << qt << endl;
    else
      cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < m; i++) {
    tmp[s[i] - 1] = c[i];
    for (int j = 0; j < m; j++) {
      if (s[i] == s[j] && c[i] >= c[j] && i != j) {
        tmp[s[i] - 1] = c[j];
      }
    }
  }
  if (tmp[0] == 0) {
    cout << "-1" << endl;
    return 0;
  } else {
    for (int i = 0; i < (int)(n); i++) {
      cout << tmp[i];
    }
    cout << endl;
  }
  return 0;
}
int min(int a[], int N, int b[]) {
  int min = 999;
  for (int i = 0; i < N && b[i] == 1; i++) {
    (min > a[i]) ? (min = a[i]) : 0;
  }
  return min;
}
