#include <bits/stdc++.h>
using namespace std;
inline void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest) {
  cin >> first;
  IN(rest...);
  return;
}
inline int p(void) {
  cout << endl;
  return 0;
}
template <class Head>
int p(Head&& head) {
  cout << head;
  p();
  return 0;
}
template <class Head, class... Tail>
int p(Head&& head, Tail&&... tail) {
  cout << head << " ";
  p(forward<Tail>(tail)...);
  return 0;
}
struct ProconInit {
  static constexpr int IOS_PREC = 15;
  static constexpr bool AUTOFLUSH = false;
  ProconInit() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(IOS_PREC);
    if (AUTOFLUSH) cout << unitbuf;
  }
} PROCON_INIT;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  return a.second < b.second;
}
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  long long N, M;
  IN(N, M);
  vector<long long> s(M), c(M);
  for (long long i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  string ans = "";
  for (long long i = 0; i < N; i++) ans += '0';
  for (long long i = 0; i < M; i++) {
    if (ans[s[i] - 1] != c[i] + '0') {
      p(-1);
      return 0;
    }
    ans[s[i] - 1] = c[i] + '0';
  }
  if (ans[0] == '0') {
    p(-1);
    return 0;
  }
  p(ans);
}
