#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
long long mod(long long a, long long b) { return (b + (a % b)) % b; }
long long mulMod(long long a, long long b) { return ((a % M) * (b % M)) % M; }
long long subMod(long long a, long long b) {
  return mod((mod(a, M) - mod(b, M)), M);
}
long long dayofweek(long long d, long long m, long long y) {
  static long long t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
  y -= m < 3;
  return (y + y / 4 - y / 100 + y / 400 + t[m - 1] + d) % 7;
}
long long gcdExtended(long long a, long long b, long long* x, long long* y);
long long modInverse(long long b, long long m) {
  long long x, y;
  long long g = gcdExtended(b, m, &x, &y);
  if (g != 1) return -1;
  return (x % m + m) % m;
}
long long modDivide(long long a, long long b, long long m) {
  a = a % m;
  long long inv = modInverse(b, m);
  return (inv * a) % m;
}
long long gcdExtended(long long a, long long b, long long* x, long long* y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
long long power(long long x, long long y) {
  long long temp;
  if (y == 0) return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return mulMod(temp, temp);
  else
    return mulMod(x, mulMod(temp, temp));
}
void test() {}
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> Min(4, 10);
  long long s, c;
  for (long long i = 0; i < m; i++) {
    cin >> s >> c;
    if (n > 1) {
      if (s == 1 && c != 0 && c < Min[s]) {
        Min[s] = c;
      } else if (s > 1 && c < Min[s]) {
        Min[s] = c;
      }
    } else {
      if (c < Min[s]) {
        Min[s] = c;
      }
    }
  }
  if (n == 1) {
    if (Min[1] != 10) {
      cout << Min[1];
    } else {
      cout << 0;
    }
  } else if (n > 1 && Min[1] != 10) {
    for (long long i = 1; i <= n; i++) {
      if (Min[i] != 10) {
        cout << Min[i];
      } else {
        cout << 0;
      }
    }
  } else {
    cout << -1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
