#include <bits/stdc++.h>
using namespace std;
auto t1 = chrono::high_resolution_clock::now();
bool prime[100001];
long long int expo(long long int a, long long int b) {
  a = a % 1000000007;
  b = b % 1000000007;
  if (b == 0) return 1;
  if (b % 2)
    return ((a % 1000000007) *
            (expo((a * a) % 1000000007, b / 2) % 1000000007)) %
           1000000007;
  return expo((a * a) % 1000000007, b >> 1) % 1000000007;
}
long long int mul(long long int a, long long int b) {
  a = a % 1000000007;
  b = b % 1000000007;
  if (b == 0) return 0;
  if (b % 2)
    return ((a % 1000000007) +
            (mul((a + a) % 1000000007, b / 2) % 1000000007)) %
           1000000007;
  return mul((a + a) % 1000000007, b >> 1) % 1000000007;
}
bool ispoweroftwo(long long int x) { return x && !(x & (x - 1)); }
long long int xorcal(long long int n) {
  if (n % 4 == 0) return n;
  if (n % 4 == 1) return 1;
  if (n % 4 == 2) return n + 1;
  if (n % 4 == 3) return 0;
}
void sieve(long long int n) {
  memset(prime, true, sizeof(prime));
  prime[0] = false;
  prime[1] = false;
  for (long long int i = 2; i * i <= n; i++) {
    if (prime[i] == true) {
      for (long long int j = i * i; j <= n; j += i) {
        prime[j] = false;
      }
    }
  }
}
bool isprime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 or n % 3 == 0) return false;
  for (long long int i = 5; i * i <= n; i += 6) {
    if (n % i == 0 or n % (i + 2) == 0) return false;
  }
  return true;
}
long long int modinverse(long long int a, long long int m) {
  long long int m0 = m;
  long long int y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long int q = a / m;
    long long int t = m;
    m = a % m;
    a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) {
    return b;
  }
  return (b % a, a);
}
long long int power(long long int A, long long int B) {
  if (A == 0) return 0;
  if (B == 0) return 1;
  long long int y;
  if (B % 2 == 0) {
    y = power(A, B / 2);
    y = (y * y) % 1000000007;
  } else {
    y = A % 1000000007;
    y = (y * power(A, B - 1) % 1000000007) % 1000000007;
  }
  return (long long int)((y + 1000000007) % 1000000007);
}
bool ispalindrome(string s) {
  string t = s;
  reverse(t.begin(), t.end());
  if (t == s) return true;
  return false;
}
void binary(long long int a[], long long int n) {
  for (long long int i = 64 - 1; i >= 0; i--) {
    long long int k = n >> i;
    a[i] = k & (long long int)1;
  }
}
long long int countBits(long long int n) {
  if (n == 0) return 0;
  return 1 + countBits(n & (n - 1));
}
bool same(string str) {
  string s = str;
  reverse(s.begin(), s.end());
  return s == str;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, m;
  cin >> n >> m;
  long long int s[m], c[m];
  vector<long long int> v(n, INT_MAX);
  map<long long int, long long int> idx;
  for (long long int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    idx[s[i]]++;
    if (idx[s[i]] > 1) {
      if (v[s[i] - 1] == c[i]) continue;
      cout << "-1" << '\n';
      exit(0);
    }
    v[s[i] - 1] = min(v[s[i] - 1], c[i]);
  }
  if (v[0] == INT_MAX or v[0] == 0) {
    cout << "-1" << '\n';
    exit(0);
  }
  cout << v[0];
  for (long long int i = 1; i < n; i++) {
    if (v[i] == INT_MAX) v[i] = 0;
    cout << v[i];
  }
  auto t2 = chrono::high_resolution_clock::now();
  auto duration = chrono::duration_cast<chrono::milliseconds>(t2 - t1).count();
  clog << "Time taken = " << duration * 1.0 / 1000 << " seconds" << endl;
  return 0;
}
