#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[20];
  bool vst[20];
  memset(vst, true, sizeof(vst));
  memset(s, 0, sizeof(s));
  bool ok = true;
  while (m--) {
    int x, y;
    cin >> x >> y;
    if (vst[x] == false && y != s[x]) ok = false;
    vst[x] = false;
    s[x] = y;
  }
  if (ok) {
    if (s[1] != 0) {
      for (int i = 1; i <= n; i++) cout << s[i];
    } else
      cout << -1;
  } else
    cout << -1;
}
