#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
long long getDigit(long long n) {
  long long cnt = 0;
  while (n != 0) {
    n /= 10;
    cnt++;
  }
  return cnt;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
bool comp(const pair<double, long long>& a, const pair<double, long long>& b) {
  if (a.first == b.first)
    return a.second > b.second;
  else {
    return a.first > b.first;
  }
}
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m), c(m);
  for (long long i = 0; i < (m); ++i) cin >> s[i] >> c[i];
  vector<char> ans(n, '#');
  for (long long i = 0; i < (m); ++i) {
    if (ans[s[i] - 1] == '#' || ans[s[i] - 1] == ('0' + c[i])) {
      ans[s[i] - 1] = '0' + c[i];
    } else {
      return cout << -1 << endl, 0;
    }
  }
  if (ans[0] == '#' || ans[0] == '0') return cout << -1 << endl, 0;
  for (long long i = 0; i < (n); ++i) {
    if (ans[i] == '#') ans[i] = '0';
  }
  string ansS;
  for (long long i = 0; i < (n); ++i) {
    ansS += ans[i];
  }
  cout << stoll(ansS) << endl;
}
