#include <bits/stdc++.h>
using namespace std;
const int Inf = 1 << 29;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, i, s, c, fd = 1;
  int d[3];
  cin >> n >> m;
  for (i = 0; i < 3; i++) d[i] = -1;
  for (i = 0; i < m; i++) {
    cin >> s >> c;
    if (d[s - 1] == -1 || d[s - 1] == c)
      d[s - 1] = c;
    else {
      fd = 0;
      break;
    }
  }
  if (!d[0] > 0) fd = 0;
  if (fd == 1) {
    for (i = 0; i < n; i++) {
      if (d[i] == -1)
        cout << 0;
      else
        cout << d[i];
    }
  } else
    cout << -1;
  return 0;
}
