#include <bits/stdc++.h>
using namespace std;
template <class T>
T GCD(T a, T b) {
  if (a == 0) return b;
  return GCD(b % a, a);
}
template <class T>
T modpow(T x, T p) {
  T res = 1;
  while (p > 0) {
    if (p & 1) res *= x;
    x *= x;
    p /= 2;
  }
  return res;
}
template <class T>
void print(T a[], long long n) {
  for (long long i = 0; i < n; i++) std::cout << a[i] << ' ';
  cout << endl;
}
template <class T>
void printc(T c) {
  for (auto const &v : c) std::cout << v << ' ';
  cout << endl;
}
struct HASH {
  size_t operator()(const pair<long, long> &x) const {
    return hash<long long>()(((long long)x.first) ^
                             (((long long)x.second) << 32));
  }
};
bool pair_sort(const pair<int, int> &p1, const pair<int, int> &p2) {
  if (p1.first != p2.first)
    return p1.first < p2.first;
  else
    return p1.second < p2.second;
}
const int INF = std::numeric_limits<int>::max();
const long long M_INF = std::numeric_limits<long long>::min();
void solution();
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solution();
  return 0;
}
void solution() {
  int n, m;
  cin >> n >> m;
  int num[n];
  memset(num, -1, sizeof num);
  bool poss = true;
  for (long long i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (num[s] == -1)
      num[s] = c;
    else if (num[s] == c)
      num[s] = c;
    else
      poss = false;
  }
  if (!poss) {
    cout << -1 << endl;
    return;
  }
  if (num[0] == 0) {
    cout << -1 << endl;
    return;
  } else if (num[0] == -1)
    num[0] = 1;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (num[i] == -1) num[i] = 0;
    ans = ans * 10 + num[i];
  }
  cout << ans << endl;
}
