#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, sg = 1;
  cin >> n >> m;
  vector<int> ls(n, -1);
  while (m--) {
    int a, b;
    cin >> a >> b;
    if (ls[a - 1] < 0 || ls[a - 1] == b)
      ls[a - 1] = b;
    else
      sg = 0;
  }
  for (int &x : ls)
    if (x < 0) sg = 0;
  if (sg && ls[0] != 0)
    for (int x : ls) cout << x;
  else
    cout << -1;
}
