#include <bits/stdc++.h>
using namespace std;
bool debug_mode = true;
void show(const vector<long long>& arr, bool show_index = false,
          long long w = 4) {
  if (!debug_mode) return;
  long long max_value = 0;
  for (int i = 0; i < ((int)(arr).size()); i++) {
    if (abs((long long)1e18 - arr[i]) >= 1e5)
      max_value = max(max_value, arr[i]);
  }
  w = max(w, ((int)(to_string(max_value)).size()) + 1LL);
  if (show_index) {
    for (int i = 0; i < arr.size(); i++) {
      cout << right << setw(w) << i;
    }
    cout << endl;
  }
  for (int i = 0; i < arr.size(); i++) {
    if (abs((long long)1e18 - arr[i]) < 1e5) {
      cout << right << setw(w) << (arr[i] == (long long)1e18 ? "INF" : "inf");
    } else {
      cout << right << setw(w) << arr[i];
    }
  }
  cout << endl;
}
void show(const vector<vector<long long>>& arr, long long w = 4) {
  if (!debug_mode) return;
  int M = arr.size(), N = arr[0].size();
  long long max_value = 0;
  for (int i = 0; i < M; i++)
    for (int j = 0; j < N; j++) {
      if (abs((long long)1e18 - arr[i][j]) >= 1e5)
        max_value = max(max_value, arr[i][j]);
    }
  w = max(w, ((int)(to_string(max_value)).size()) + 1LL);
  cout << right << setw(w) << "#";
  for (int i = 0; i < ((int)(arr[0]).size()); i++) {
    cout << right << setw(w) << i;
  }
  cout << endl;
  for (int i = 0; i < ((int)(arr).size()); i++) {
    cout << right << setw(w) << i;
    for (int j = 0; j < ((int)(arr[0]).size()); j++) {
      if (abs((long long)1e18 - arr[i][j]) < 1e5) {
        cout << right << setw(w)
             << (arr[i][j] == (long long)1e18 ? "INF" : "inf");
      } else {
        cout << right << setw(w) << arr[i][j];
      }
    }
    cout << endl;
  }
  cout << endl;
}
void show(const vector<vector<vector<long long>>>& arr, long long w = 4) {
  if (!debug_mode) return;
  for (int i = 0; i < arr.size(); i++) {
    cout << "i: " + to_string(i) << "\n";
    ;
    show(arr[i], w);
  }
  cout << endl;
}
inline vector<vector<vector<long long>>> make_vector(long long i, long long j,
                                                     long long k) {
  vector<vector<vector<long long>>> v(
      i, vector<vector<long long>>(j, vector<long long>(k, 0)));
  return v;
}
inline vector<vector<long long>> make_vector(long long i, long long j) {
  vector<vector<long long>> v(i, vector<long long>(j, 0));
  return v;
}
template <class InputIterator>
InputIterator adv(
    InputIterator x,
    typename std::iterator_traits<InputIterator>::difference_type n) {
  advance(x, n);
  return x;
}
class mod {
  static long long fact[];

 public:
  template <class... A>
  static long long mul(A... args) {
    long long res = 1;
    for (long long i : std::initializer_list<long long>{args...}) {
      res = (res * i) % ((long long)1e9 + 7);
    }
    return res;
  }
  static long long power(long long base, long long exp) {
    if (exp == 0) return 1;
    if (exp & 1) {
      return mul(base, power(base, exp - 1));
    } else {
      long long p = power(base, exp / 2);
      return mul(p, p);
    }
  }
  static void calc_factorial(int n) {
    fact[0] = 1;
    for (int i = 1; i < n + 1; i++) {
      fact[i] = mul(fact[i - 1], i);
    }
  }
  static long long factorial(int n) {
    if (fact[n] != 0) return fact[n];
    if (n == 0) return 1;
    return fact[n] = mul(n, factorial(n - 1));
  }
  static long long inverse(int n) { return power(n, ((long long)1e9 + 7) - 2); }
  static long long comb(int n, int r) {
    if (r < 0 || r > n) return 0;
    return mul(factorial(n), inverse(factorial(n - r)), inverse(factorial(r)));
  }
  template <class... A>
  static long long div(long long dividend, A... args) {
    long long res = dividend;
    for (long long i : std::initializer_list<long long>{args...}) {
      res = mul(res, inverse(i));
    }
    return res;
  }
  template <class... A>
  static long long add(A... args) {
    long long res = 0;
    for (long long i : std::initializer_list<long long>{args...}) {
      res = (res + i) % ((long long)1e9 + 7);
    }
    return res;
  }
  template <class... A>
  static long long sub(long long l, A... args) {
    long long res = l;
    for (long long i : std::initializer_list<long long>{args...}) {
      res = (res - i + ((long long)1e9 + 7)) % ((long long)1e9 + 7);
    }
    return res;
  }
};
long long mod::fact[(int)2e6 + 1];
int ni() {
  int i;
  cin >> i;
  return i;
}
long long nll() {
  long long l;
  cin >> l;
  return l;
}
class math {
 public:
  static long long floor(long long a, long long b) {
    if (b < 0) {
      a *= -1;
      b *= -1;
    }
    if (a > 0) {
      return a / b;
    } else {
      return (a - b + 1) / b;
    }
  }
  static long long ceil(long long a, long long b) {
    if (b < 0) {
      a *= -1;
      b *= -1;
    }
    if (a > 0) {
      return (a + b - 1) / b;
    } else {
      return a / b;
    }
  }
  static long long gcd(long long a, long long b) {
    long M = max(a, b);
    long m = min(a, b);
    if (m == 0) {
      return M;
    }
    return gcd(m, M % m);
  }
  static long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
  static long long sqrt(long long n) {
    long long high = (1LL << (31)) + 1;
    long long low = 0;
    long long mid;
    while (high - low > 1) {
      mid = (high + low) / 2;
      if (mid * mid <= n) {
        low = mid;
      } else {
        high = mid;
      }
    }
    return low;
  }
};
template <class T, class F>
long long binary_count(const vector<T>& A, const F& f) {
  int N = ((int)(A).size());
  bool first = f(A[0]);
  bool last = f(A[N - 1]);
  if (first && last) return N;
  if (!first && !last) return 0;
  int ok, ng, mid;
  if (last) {
    ok = N - 1;
    ng = 0;
  } else {
    ok = 0;
    ng = N - 1;
  }
  while (abs(ok - ng) > 1) {
    mid = (ok + ng) / 2;
    if (f(A[mid])) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return (first ? ok + 1 : N - ok);
}
int main() {
  int N = ni();
  int M = ni();
  vector<int> s(N, -1);
  bool valid = true;
  for (int i = 0; i < M; i++) {
    int si = ni() - 1;
    int ci = ni();
    if (s[si] != -1 && s[si] != ci) {
      valid = false;
      break;
    }
    s[si] = ci;
  }
  if (s[0] == 0) valid = false;
  if (!valid) {
    cout << -1 << "\n";
    ;
  } else if (N == 1) {
    if (s[0] == -1) {
      cout << 0 << "\n";
      ;
    } else {
      cout << s[0] << "\n";
      ;
    }
  } else {
    for (int i = 0; i < N; i++) {
      if (s[i] == -1) {
        if (i == 0)
          cout << 1;
        else
          cout << 0;
      } else {
        cout << s[i];
      }
    }
    cout << endl;
  }
  return 0;
}
