#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
struct cinacc {
  cinacc() {
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
} cinaccc;
struct coutacc {
  coutacc() {
    cout.setf(ios::fixed);
    cout.precision(12);
  }
} coutaccc;
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 isPrime(int n) {
  if (n < 2)
    return false;
  else if (n == 2)
    return true;
  else if (n % 2 == 0)
    return false;
  double sqrtNum = sqrt(n);
  for (int i = 3; i <= sqrtNum; i += 2)
    if (n % i == 0) return false;
  return true;
}
template <class T>
vector<T> sortVector(vector<T> v, bool b = true) {
  if (b)
    sort(v.begin(), v.end());
  else
    sort(v.begin(), v.end(), greater<T>());
  return v;
}
vector<unsigned long long> z_algorithm(string s) {
  vector<unsigned long long> a(s.length());
  a[0] = s.size();
  for (unsigned long long i = 1, j = 0, k; i < s.size();) {
    while (i + j < s.size() && s[j] == s[i + j]) ++j;
    a[i] = j;
    k = !!j;
    while (i + k < s.size() && k + a[k] < j) a[i + k] = a[k], ++k;
    i += k + !j;
    j -= k;
  }
  return a;
}
int solve(int n, int m, vector<int> s, vector<int> c) {
  for (int i = 0; i < (int)(m); i++) {
    if (s[i] == 1 && c[i] == 0) return -1;
  }
  for (int i = 0; i < (int)(m); i++) {
    for (int j = 0; j < (int)(m); j++) {
      if (i != j && s[i] == s[j]) {
        if (c[i] != c[j]) return -1;
      }
    }
  }
  int t[10] = {0};
  bool tb[10] = {false};
  for (int j = 0; j < (int)(m); j++) {
    t[s[j] - 1] = c[j];
    tb[s[j] - 1] = true;
  }
  int v[] = {1, 10, 100};
  int ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    if (tb[i]) ans += t[i] * v[n - i - 1];
  }
  return ans;
}
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i] >> c[i];
  }
  cout << solve(n, m, s, c);
  return 0;
}
