#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &res) {
  res = 0;
  bool bo = 0;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  if (c == '-')
    bo = 1;
  else
    res = c - 48;
  while ((c = getchar()) >= '0' && c <= '9')
    res = (res << 3) + (res << 1) + (c - 48);
  if (bo) res = ~res + 1;
}
template <typename T>
T Abs(T x) {
  return x < 0 ? -x : x;
}
template <typename T>
T Max(T a, T b) {
  return a > b ? a : b;
}
const int N = 2e5 + 5;
int x, len, _, n, d, k, m, l, c, cs = 1;
int track[11];
void Solve() {
  int n, m, s, c;
  read(n);
  read(m);
  int flag = 1;
  for (int i = 0; i < 11; ++i) track[i] = -1;
  for (int i = m; i; i--) {
    read(s);
    read(c);
    if (0 == flag) continue;
    if (track[s] == -1 or track[s] == c)
      track[s] = c;
    else
      flag = 0;
  }
  if (!flag) {
    cout << "-1\n";
    return;
  }
  if (n == 1) {
    track[1] == -1 ? cout << "0" : cout << track[1];
    cout << endl;
  }
  for (int i = 1; i <= n; ++i) {
    if (i > 1)
      track[i] == -1 ? cout << 0 : cout << track[i];
    else
      track[i] == -1 ? cout << 1 : cout << track[i];
  }
  cout << "\n";
}
signed main() {
  Solve();
  return 0;
}
