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