#include <bits/stdc++.h>
using namespace std;
inline bool valid(int x, int n) { return 0 <= x && x < n; }
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
template <typename T>
inline T pop(queue<T>& q) {
  T front = q.front();
  q.pop();
  return front;
}
template <typename T>
inline T gcd(T a, T b) {
  for (; b; a %= b, swap(a, b))
    ;
  return a;
}
template <typename T>
tuple<T, T, T> xgcd(T a, T b) {
  if (b == 0) return {1, 0, a};
  T x, y, g;
  tie(x, y, g) = xgcd(b, a % b);
  return {y, x - (a / b) * y, g};
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int N, M;
  cin >> N >> M;
  vector<long long> rst(N + 1, 0);
  vector<bool> visit(N + 1, 0);
  while (M--) {
    int s, c;
    cin >> s >> c;
    if (visit[s]) {
      if (rst[s] == c)
        continue;
      else {
        cout << -1;
        return 0;
      }
    }
    visit[s] = 1;
    rst[s] = c;
  }
  if (N > 1 && rst[1] == 0) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= N; i++) cout << rst[i];
}
