#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int a[n];
  for (int i = 0; i < n; i++) a[i] = 100;
  for (int i = 0; i < m; i++) {
    a[s[i] - 1] = min(a[s[i] - 1], c[i]);
  }
  if (a[0] == 100 || a[0] == 0)
    puts("-1");
  else {
    for (int i = 0; i < n; i++) {
      if (a[i] == 100)
        cout << 0;
      else
        cout << a[i];
    }
    cout << "\n";
  }
}
