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