#include <bits/stdc++.h>
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;
long long int fac[MAX], finv[MAX], inv[MAX];
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
bool palindrome(string s) {
  bool flag = true;
  for (long long int i = 0; i < (s.size()); i++)
    if (s[i] != s[s.size() - 1 - i]) flag = false;
  return flag;
}
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long int Len(long long int n) {
  long long int s = 0;
  while (n != 0) s++, n /= 10;
  return s;
}
long long int Sint(long long int n) {
  long long int m = 0, s = 0, a = n;
  while (a != 0) s++, a /= 10;
  for (long long int i = s - 1; i >= 0; i--)
    m += n / ((long long int)pow(10, i)) -
         (n / ((long long int)pow(10, i + 1))) * 10;
  return m;
}
long long int Svec(vector<long long int> v) {
  long long int n = 0;
  for (long long int i = 0; i < v.size(); i++) n += v[i];
  return n;
}
long long int GCD(long long int a, long long int b) {
  return b ? GCD(b, a % b) : a;
}
long long int LCM(long long int a, long long int b) {
  return a / GCD(a, b) * b;
}
long long int Factorial(long long int n) {
  long long int m = 1;
  while (n >= 1) m *= n, n--;
  return m;
}
void runlength(string s, vector<pair<char, long long int>>& p) {
  long long int x = 1;
  if (s.size() == 1) {
    p.push_back(pair<char, long long int>(s[0], 1));
  }
  for (long long int i = 0; i < s.size() - 1; i++) {
    if (s[i] == s[i + 1]) {
      x++;
      if (i == s.size() - 2) {
        p.push_back(pair<char, long long int>(s[i], x));
      }
    } else {
      p.push_back(pair<char, long long int>(s[i], x));
      x = 1;
      if (i == s.size() - 2) {
        p.push_back(pair<char, long long int>(s[s.size() - 1], x));
      }
    }
  }
}
long long int COM(long long int n, long long int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long int modpow(long long int a, long long int n, long long int mod) {
  long long int res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
string Toupper(string s) {
  string ans = "";
  for (long long int i = 0; i < (s.size()); i++) {
    if ('a' <= s[i] && s[i] <= 'z')
      ans += (char)s[i] - 32;
    else
      ans += s[i];
  }
  return ans;
}
string Tolower(string s) {
  string ans = "";
  for (long long int i = 0; i < (s.size()); i++) {
    if ('A' <= s[i] && s[i] <= 'Z')
      ans += (char)s[i] + 32;
    else
      ans += s[i];
  }
  return ans;
}
const int MAX_N = 100010;
vector<bool> sieve_of_eratosthenes() {
  vector<bool> isPrime(MAX_N + 1, true);
  for (int i = 2; i <= MAX_N; i++) {
    if (isPrime[i]) {
      for (int j = 2 * i; j <= MAX_N; j += i) {
        isPrime[j] = false;
      }
    }
  }
  return isPrime;
}
vector<pair<long long int, long long int>> prime_factorize(long long int n) {
  vector<pair<long long int, long long int>> ans;
  for (long long int p = 2; p <= sqrt(n); p++) {
    if (n % p != 0) continue;
    long long int cnt = 0;
    while (n % p == 0) {
      n /= p;
      cnt++;
    }
    ans.push_back(make_pair(p, cnt));
  }
  if (n != 1) ans.push_back(make_pair(n, 1));
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, m;
  cin >> n >> m;
  vector<long long int> s(m), c(m);
  for (long long int i = 0; i < (m); i++) cin >> s[i] >> c[i];
  if (n == 1) {
    long long int ans = 0;
    for (long long int i = 0; i < (m); i++) {
      if (ans == 0 || ans == c[i]) {
        ans = c[i];
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  } else if (n == 2) {
    long long int ans = 0;
    for (long long int i = 0; i < (m); i++) {
      if (s[i] == 1) {
        if (c[i] == 0) {
          cout << -1 << endl;
          return 0;
        }
        if (ans / 10 == 0) {
          ans += c[i] * 10;
        } else if (ans / 10 != c[i]) {
          cout << -1 << endl;
          return 0;
        }
      } else if (s[i] == 2) {
        if (ans % 10 == 0) {
          ans += c[i];
        } else if (ans % 10 != c[i]) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
    if (ans < 10) {
      ans += 10;
    }
    cout << ans << endl;
  } else if (n == 3) {
    long long int ans = 0;
    for (long long int i = 0; i < (m); i++) {
      if (s[i] == 1) {
        if (c[i] == 0) {
          cout << -1 << endl;
          return 0;
        }
        if (ans / 100 == 0) {
          ans += c[i] * 100;
        } else if (ans / 100 != c[i]) {
          cout << -1 << endl;
          return 0;
        }
      } else if (s[i] == 2) {
        if (ans % 100 - ans % 10 == 0) {
          ans += c[i] * 10;
        } else if (ans % 100 - ans % 10 != c[i]) {
          cout << -1 << endl;
          return 0;
        }
      } else if (s[i] == 3) {
        if (ans % 10 == 0) {
          ans += c[i];
        } else if (ans % 10 != c[i]) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
    if (ans < 100) {
      ans += 100;
    }
    cout << ans << endl;
  }
}
