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