#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll INF = 1000000000;
const ld PI = (acos(-1));
using Graph = vector<vector<int>>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
double rad(double a) { return a * 180 / PI; }
struct UnionFind {
  vector<int> par;
  UnionFind(int N) : par(N) {
    for (int i = 0; i < N; i++) par[i] = i;
  }
  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
  }
  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};
int dp[100050];
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  vector<int> ans(N, 0);
  vector<bool> hoge(N, false);
  bool flag = true;
  for (int i = 0; i < (M); i++) cin >> s.at(i) >> c.at(i);
  for (int i = 0; i < (M); i++) s.at(i)--;
  for (int i = 0; i < M; i++) {
    if (!hoge.at(s.at(i)) && !(s.at(i) == 0 && c.at(i) == 0)) {
      ans.at(s.at(i)) = c.at(i);
      hoge.at(s.at(i)) = true;
    } else {
      if (ans.at(s.at(i)) != c.at(i)) {
        flag = false;
        break;
      } else {
        ans.at(s.at(i)) = c.at(i);
        hoge.at(s.at(i)) = true;
      }
    }
  }
  if (flag) {
    for (int i = 0; i < (M); i++) {
      cout << ans.at(i);
    }
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
