#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
bool isPalindrome(string str) {
  long long int l = 0;
  long long int h = str.length() - 1;
  while (h > l) {
    if (str[l++] != str[h--]) {
      return false;
    }
  }
  return true;
}
bool isPrime(long long int n) {
  if (n == 2) return true;
  if (n % 2 == 0) return false;
  for (long long int i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0) return false;
  }
  return true;
}
long long int countGreater(long long int arr[], long long int n,
                           long long int k) {
  long long int l = 0;
  long long int r = n - 1;
  long long int leftGreater = n;
  while (l <= r) {
    long long int m = l + (r - l) / 2;
    if (arr[m] > k) {
      leftGreater = m;
      r = m - 1;
    } else
      l = m + 1;
  }
  return (n - leftGreater);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long int n, m;
  cin >> n >> m;
  map<long long int, long long int> mm1, mm2;
  for (long long int i = 0; i < n; i++) mm1[i] = -1;
  for (long long int i = 0; i < m; i++) {
    long long int ind, val;
    cin >> ind >> val;
    if (ind == 1 && val == 0 && n != 1) {
      cout << -1 << endl;
      return 0;
    }
    if (mm1[ind - 1] == -1)
      mm1[ind - 1] = val;
    else {
      if (mm1[ind - 1] != val) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (n == 1 && mm1[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (long long int i = 1; i <= pow(10, n) - 1; i++) {
    mm2.clear();
    long long int temp = i;
    long long int ind = 0;
    for (long long int j = 0; j < n; j++) {
      mm2[n - 1 - j] = temp % 10;
      temp /= 10;
    }
    long long int cnt = 0;
    bool lz = true;
    for (long long int j = 0; j < n; j++) {
      if ((mm2[j] == 0) && lz) break;
      if (mm2[j] != 0) lz = false;
      if (mm1[j] == mm2[j] || mm1[j] == -1) {
        cnt++;
      }
    }
    if (cnt == n) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
