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