#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, m, s[1000], c[1000], a = 1000000000LL, b = 1000000000LL,
                                    d = 1000000000LL;
  long long z = 0, x = 0, y = 0, aa = 0, bb = 0, dd = 0;
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    cin >> s[i] >> c[i];
  }
  if (n == 1) {
    if (m == 1) {
      if (c[1] != 0) {
        cout << c[1] << "\n";
      } else {
        cout << "-1\n";
      }
    } else {
      cout << "0\n";
    }
  } else if (n == 2) {
    for (long long i = 1; i <= m; i++) {
      if (s[i] == 1) {
        a = c[i];
        if (aa != 0 && c[aa] != a) {
          aa = 1;
          break;
        }
        aa = i;
        z++;
      } else if (s[i] == 2) {
        b = c[i];
        if (bb != 0 && c[bb] != b) {
          bb = 1;
          break;
        }
        bb = i;
        x++;
      }
    }
    if (a == 0 || aa == 1 || bb == 1) {
      cout << "-1\n";
    } else if (z > 0 && x > 0) {
      cout << a << b << "\n";
    } else if (z > 0 && x == 0) {
      cout << a << "0\n";
    } else if (z == 0 && x > 0) {
      cout << "1" << b << "\n";
    } else {
      cout << "10\n";
    }
  } else {
    for (long long i = 1; i <= m; i++) {
      if (s[i] == 1) {
        a = c[i];
        if (aa != 0 && c[aa] != a) {
          aa = 1;
          break;
        }
        aa = i;
        z++;
      } else if (s[i] == 2) {
        b = c[i];
        if (bb != 0 && c[bb] != b) {
          bb = 1;
          break;
        }
        bb = i;
        x++;
      } else if (s[i] == 3) {
        d = c[i];
        if (dd != 0 && c[dd] != d) {
          dd = 1;
          break;
        }
        dd = i;
        y++;
      }
    }
    if (a == 0 || aa == 1 || bb == 1 || dd == 1) {
      cout << "-1\n";
    } else if (y > 0 && x > 0 && z == 0) {
      cout << "1" << b << c << "\n";
    } else if (y > 0 && x == 0 && z > 0) {
      cout << a << "0" << d << "\n";
    } else if (y == 0 && x > 0 && z > 0) {
      cout << a << b << "0\n";
    } else if (y > 0 && x == 0 && z == 0) {
      cout << "1"
           << "0" << c << "\n";
    } else if (y == 0 && x > 0 && z == 0) {
      cout << "1" << b << "0\n";
    } else if (y == 0 && x == 0 && z > 0) {
      cout << a << "00\n";
    } else if (y > 0 && x > 0 && z > 0) {
      cout << a << b << d << "\n";
    } else {
      cout << "100\n";
    }
  }
}
