#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline int read() {
  int x = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return w == 1 ? x : -x;
}
int ans[1000005], vis[1000005], f;
int main() {
  int n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    int a = read(), b = read();
    if (a > n) {
      f = 1;
      continue;
    }
    if (vis[a]) {
      if (ans[a] == b)
        continue;
      else
        f = 1;
    } else {
      ans[a] = b;
      vis[a] = 1;
    }
  }
  if (vis[1] == 1 && ans[1] == 0 && n == 1) {
    puts("0");
    return 0;
  } else if (vis[1] == 1 && ans[1] == 0) {
    puts("-1");
    return 0;
  }
  if (f == 1) {
    puts("-1");
    return 0;
  }
  if (vis[1] == 1)
    cout << ans[1];
  else
    cout << 1;
  for (int i = 2; i <= n; i++)
    if (vis[i])
      cout << ans[i];
    else
      cout << 0;
  return 0;
}
