#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int M = 2e2 + 5;
const int INF = 0x7fffffff;
const int mod = 1e9 + 7;
const int sz = 18;
const double eps = 1e-10;
const double pi = acos(-1);
int n, m;
char str[N];
int f[N];
map<int, pair<long long, long long> > mm;
template <class T>
inline void read(T &x) {
  char c;
  x = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') x = -1;
  T res = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
  x *= res;
}
int main() {
  read(n);
  read(m);
  bool flag = 1;
  memset(f, -1, sizeof f);
  for (int i = 1; i <= m; i++) {
    int a, b;
    read(a);
    read(b);
    if (!flag) continue;
    if (f[a] == -1)
      f[a] = b;
    else {
      if (f[a] == b) continue;
      flag = 0;
    }
  }
  if (flag == 0) {
    cout << -1 << endl;
  } else {
    for (int i = 1; i <= n; i++) {
      if (f[i] == -1) {
        if (i == 1)
          cout << 1;
        else
          cout << 0;
      } else
        cout << f[i];
    }
    cout << endl;
  }
  return 0;
}
