#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar();
  x *= f;
  return;
}
template <typename T>
void write(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
  return;
}
int n, m;
int a[10];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    if (a[x] && a[x] != y) {
      cout << -1 << endl;
      return 0;
    }
    if (x == 1 && y == 0 && n != 1) {
      cout << -1 << endl;
      return 0;
    }
    a[x] = y;
  }
  for (int i = 1; i <= n; i++) cout << a[i];
  cout << endl;
  return 0;
}
