#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
const int INF = 0x3f3f3f3f;
const int MAXINT = 2147483647;
const int mod = 1000000007;
const long long MAXLONG = 9223372036854775807;
template <class T>
inline bool read(T &ret) {
  char c;
  int sgn;
  if (static_cast<void>(c = getchar()), c == EOF) return 0;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (static_cast<void>(c = getchar()), c >= '0' && c <= '9')
    ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}
template <class T>
inline void write(T x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
void slove(int question_num) {
  while (question_num--) {
    map<int, int> s;
    int n, m;
    cin >> n >> m;
    int flag = 0, flag2 = 0;
    for (int i = 1; i <= m; ++i) {
      int a, b;
      cin >> a >> b;
      if (b) flag2 = 1;
      if (s.count(a) && s[a] != b) {
        flag = 1;
      } else
        s[a] = b;
    }
    if (flag)
      cout << -1;
    else {
      if (n == 1 && s[1] == 0)
        cout << 0;
      else {
        if (s.count(1) && s[1] == 0)
          cout << -1;
        else {
          for (int i = 1; i <= n; ++i) {
            if (s.count(i))
              cout << s[i];
            else
              cout << 0;
          }
        }
      }
    }
  }
}
int main() {
  int num = 1;
  slove(num);
  return 0;
}
