#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long keta(long long n) {
  string s = to_string(n);
  long long num = s.size();
  return num;
}
const long long INF = 1LL << 60;
const int dh[4] = {1, 0, -1, 0};
const int dw[4] = {0, 1, 0, -1};
struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
using P = pair<long long, int>;
class UnionFind {
 public:
  vector<int> Parent;
  UnionFind(int n) { Parent = vector<int>(n, -1); }
  int root(int a) {
    if (Parent[a] < 0)
      return a;
    else
      return Parent[a] = root(Parent[a]);
  }
  int size(int a) { return -Parent[root(a)]; }
  bool merge(int a, int b) {
    a = root(a);
    b = root(b);
    if (a == b) return false;
    if (size(a) < size(b)) swap(a, b);
    Parent[a] += Parent[b];
    Parent[b] = a;
    return true;
  }
};
const int MAX = 5e5;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % (1000000007);
    inv[i] = (1000000007) -
             inv[(1000000007) % i] * ((1000000007) / i) % (1000000007);
    finv[i] = finv[i - 1] * inv[i] % (1000000007);
  }
}
long long COM(long long n, long long k) {
  if (n >= MAX) {
    long long tmp = 1;
    for (int i = 0; i < k; i++) {
      tmp *= (n - i);
      tmp %= (1000000007);
    }
    return tmp * finv[k] % (1000000007);
  }
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % (1000000007)) % (1000000007);
}
long long POW(long long x, long long n) {
  long long ret = 1;
  while (0 < n) {
    if (n % 2 == 0) {
      x = x * x % (1000000007);
      n = n >> 1;
    } else {
      ret = ret * x % (1000000007);
      n--;
    }
  }
  return ret;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  bool ok = true;
  vector<int> ans(n, -1);
  for (int i = 0; i < m; i++) {
    s[i]--;
    if (s[i] == 0 && c[i] == 0) ok = false;
    if (ans[s[i]] != -1 && ans[s[i]] != c[i]) ok = false;
    ans[s[i]] = c[i];
  }
  if (ok == false) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (ans[i] == -1) {
      if (i == 0) cout << 1;
      if (i > 0) cout << 0;
    } else {
      cout << ans[i];
    }
  }
  cout << endl;
}
