#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
int n, m, t;
int v[MAXN];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) v[i] = -1;
  int flag = 1;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    if (v[a] == -1 || v[a] == b)
      v[a] = b;
    else
      flag = 0;
  }
  int zero = 1;
  for (int i = 1; i <= n; i++) {
    if (v[i] != 0 && v[i] != -1) zero = 0;
    if (zero == 1 && v[i] == 0) flag = 0;
  }
  if (flag) {
    for (int i = 1; i <= n; i++) {
      if (v[i] != -1)
        cout << v[i];
      else
        cout << 0;
    }
  } else
    cout << -1;
}
