#include <bits/stdc++.h>
#pragma GCC optimize("O999")
const int INF = 0x3f3f3f3f;
const int maxn = 50000005;
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n, m, x, y;
  cin >> n >> m;
  int a[n + 1];
  for (int i = 1; i <= n; i++) a[i] = 0;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    if (a[x] != 0 && a[x] != y) {
      cout << -1 << endl;
      return 0;
    }
    a[x] = y;
  }
  int i = 1;
  while (i <= n) {
    if (a[i] != 0) break;
    i++;
  }
  if (i != 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) cout << a[i];
  return 0;
}
