#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int man = 2e5 + 10;
template <typename T>
inline T read() {
  T sum = 0, fl = 1;
  int ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') fl = -1;
  for (; isdigit(ch); ch = getchar()) sum = sum * 10 + ch - '0';
  return sum * fl;
}
template <typename T>
inline void write(T x) {
  static int sta[35];
  int top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + 48);
}
template <typename T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T exgcd(T a, T b, T &g, T &x, T &y) {
  if (!b) {
    g = a, x = 1, y = 0;
  } else {
    exgcd(b, a % b, g, y, x);
    y -= x * (a / b);
  }
}
const long long mod = 1e9 + 7;
int a[10];
int main() {
  int n, m;
  cin >> n >> m;
  if (!m) {
    cout << "0" << endl;
    return 0;
  }
  memset(a, -1, sizeof(a));
  for (int i = 1; i <= m; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && a[1] <= 0) {
      a[1] = c;
      continue;
    } else if (s == 1 && c) {
      a[1] = min(a[1], c);
      continue;
    } else if (s == 1)
      continue;
    if (a[s] == -1)
      a[s] = c;
    else
      a[s] = min(a[s], c);
  }
  if (a[n] == -1) {
    cout << -1 << endl;
    return 0;
  }
  string ans = "";
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1) a[i] = 0;
    ans += a[i] + '0';
  }
  int i = 0;
  while (i < ans.size()) {
    if (ans[i] == '0') {
      ans.erase(0, 1);
    } else
      break;
  }
  if (ans.size() == 0) ans = "0";
  if (ans.size() != n) {
    cout << -1 << endl;
  } else
    cout << ans << endl;
  return 0;
}
