#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1.0);
const long long int MAX = 9000000000000000000;
const long long int MIN = -9000000000000000000;
const long double DMAX = 4500;
const long double DMIN = -4500;
const long long int MOD = 1000000007;
const long long int INF = INT_MAX;
const long long int LLINF = 1LL << 60;
const long double EPS = 1e-9;
long long int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
long long int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <typename T>
T Sum(vector<T> n, long long int a = 0, long long int b = 0) {
  if (b == 0) {
    return (accumulate(n.begin() + a, n.end(), 0));
  } else {
    return (accumulate(n.begin() + a, n.begin() + b, 0));
  }
}
template <>
long double Sum(vector<long double> n, long long int a, long long int b) {
  if (b == 0) {
    return (accumulate(n.begin() + a, n.end(), 0.));
  } else {
    return (accumulate(n.begin() + a, n.begin() + b, 0.));
  }
}
template <typename T>
void Sort(T &n, long long int a = 0, long long int b = 0) {
  if (b == 0) {
    return (sort(n.begin() + a, n.end()));
  } else {
    return (sort(n.begin() + a, n.begin() + b));
  }
}
template <typename T>
void Down(T &n, long long int a = 0, long long int b = 0) {
  if (b == 0) {
    return (sort(n.begin() + a, n.end(), greater<long long int>()));
  } else {
    return (sort(n.begin() + a, n.begin() + b, greater<long long int>()));
  }
}
template <typename T>
void Reve(T &n, long long int a = 0, long long int b = 0) {
  if (b == 0) {
    return (reverse(n.begin() + a, n.end()));
  } else {
    return (reverse(n.begin() + a, n.begin() + b));
  }
}
template <typename T, typename U>
void Copy(T &n, U &m, long long int a = 0, long long int b = 0) {
  copy(n.begin(), n.end(), m.begin());
}
template <typename T>
void V(T &n) {
  for (long long int i = 0; i < n.size(); i++) {
    cin >> n[i];
  }
}
template <typename T, typename U>
void V2(T &n, U &m) {
  for (long long int i = 0; i < n.size(); i++) {
    cin >> n[i] >> m[i];
  }
}
template <typename T, typename U, typename W>
void V3(T &n, U &m, W &p) {
  for (long long int i = 0; i < n.size(); i++) {
    cin >> n[i] >> m[i] >> p[i];
  }
}
template <typename T>
void VV(T &n, long long int size) {
  for (long long int i = 0; i < n.size(); i++) {
    for (long long int j = 0; j < size; j++) {
      cin >> n[i][j];
    }
  }
}
template <typename T>
void Rool(T &n, T &m, long long int height, long long int width) {
  for (long long int i = 0; i < width; i++) {
    for (long long int j = 0; j < height; j++) {
      m[i][j] = n[height - j - 1][i];
    }
  }
}
void fYn(bool a) {
  if (a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  exit(0);
}
long long int C45(long double n) { return round(n); }
long long int Up(long long int a, long long int b) { return ((a + b - 1) / b); }
bool IsPrime(long long int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  long double sqrtNum = sqrt(num);
  for (long long int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) return false;
  }
  return true;
}
long long int GetDigit(long long int num) { return log10(num) + 1; }
long long int KSum(long long int n) {
  long long int sum = 0;
  if (n < 0) return 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
vector<long long int> enum_div(long long int n) {
  vector<long long int> ret;
  for (long long int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(begin(ret), end(ret));
  return ret;
}
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int ngcd(vector<long long int> a) {
  long long int res;
  res = a[0];
  for (long long int i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
long long int lcm(long long int a, long long int b) {
  return a * b / gcd(a, b);
}
long long int nlcm(vector<long long int> numbers) {
  long long int res;
  res = numbers[0];
  for (long long int i = 1; i < numbers.size(); i++) {
    res = lcm(res, numbers[i]);
  }
  return res;
}
long long int modpow(long long int x, long long int n,
                     long long int mod = MAX) {
  long long int res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
long long int modinv(long long int a, long long int mod) {
  long long int b = mod, u = 1, v = 0;
  while (b) {
    long long int t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0) u += mod;
  return u;
}
long long int modlog(long long int a, long long int b, long long int m) {
  a %= m, b %= m;
  long long int lo = -1, hi = m;
  while (hi - lo > 1) {
    long long int mid = (lo + hi) / 2;
    if (mid * mid >= m)
      hi = mid;
    else
      lo = mid;
  }
  long long int sqrtM = hi;
  map<long long int, long long int> apow;
  long long int amari = 1;
  for (long long int r = 0; r < sqrtM; ++r) {
    if (!apow.count(amari)) apow[amari] = r;
    (amari *= a) %= m;
  }
  long long int A = modpow(modinv(a, m), sqrtM, m);
  amari = b;
  for (long long int q = 0; q < sqrtM; ++q) {
    if (apow.count(amari)) {
      long long int res = q * sqrtM + apow[amari];
      if (res > 0) return res;
    }
    (amari *= A) %= m;
  }
  return -1;
}
long long int factorial(long long int n) {
  if (n > 0)
    return n * factorial(n - 1);
  else
    return 1;
}
long long int perm(long long int a, long long int b) {
  return (factorial(a) / factorial(a - b));
}
long long int comb(long long int a, long long int b) {
  return (factorial(a) / (factorial(a - b) * factorial(b)));
}
long long int sigma(long long int n, long long int m) {
  return ((n + m) * (m - n + 1) * 0.5);
}
long double hope(long double a) { return (sigma(1, a) / a); }
void Main() {
  long long int n, m;
  cin >> n >> m;
  vector<long long int> s(m), c(m);
  V2(s, c);
  vector<string> A;
  map<long long int, long long int> ans;
  for (long long int i = 0; i < (m); ++i) {
    if (s[i] == 1 && c[i] == 0) continue;
    if (ans.count(s[i] - 1)) {
      if (ans[s[i] - 1] > c[i]) {
        ans[s[i] - 1] = c[i];
      }
    } else {
      ans[s[i] - 1] = c[i];
    }
  }
  for (long long int i = 0; i < (n); ++i) {
    if (ans.count(i)) {
      cout << ans[i];
    } else {
      if (i == 0) {
        cout << (-1) << endl;
        exit(0);
      } else {
        cout << ans[i];
      }
    }
  }
  cout << ("") << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(0);
  Main();
  return 0;
}
