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