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