#include <bits/stdc++.h>
using namespace std;
void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head &&head, Tail &&...tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto &vec : df) {
    print(vec);
  }
}
using ll = long long;
const int INF = 1001001001;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M);
  vector<int> C(M, -1);
  for (int i = 0, i_len = (M); i < i_len; ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    S[i] = s;
    if (S[i] != 0 && C[i] != -1)
      C[i] = min(C[i], c);
    else
      C[i] = c;
  }
  vector<int> num(N, 0);
  for (int i = 0, i_len = (M); i < i_len; ++i) {
    num[S[i]] = C[i];
  }
  int ans = 0;
  reverse(num.begin(), num.end());
  if (num[0] == 0) {
    print(-1);
    return 0;
  }
  for (int k = 0, k_len = (N); k < k_len; ++k) {
    ans += num[k] * pow(10, k);
  }
  print(ans);
  return 0;
}
