#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, flag = 0;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int tmp[n], rsv[n];
  for (int i = 0; i < n; i++) {
    tmp[i] = 0;
    rsv[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    if (s[i] == 1 & c[i] == 0) {
      flag = 1;
      break;
    }
    if (rsv[s[i] - 1] == 0) {
      tmp[s[i] - 1] = c[i];
      rsv[s[i] - 1] = 1;
    } else {
      if (tmp[s[i] - 1] != c[i]) {
        flag = 1;
        break;
      }
    }
  }
  if (n > 1 & tmp[0] == 0) {
    tmp[0] = 1;
  }
  if (flag == 1) {
    cout << -1;
  } else {
    for (int i = 0; i < n; i++) {
      cout << tmp[i];
    }
  }
}
