#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
ll f = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  int ans;
  if (N == 1) {
    ans = 1;
  }
  if (N == 2) {
    ans = 10;
  }
  if (N == 3) {
    ans = 100;
  }
  int s, c;
  int o = 0;
  int a = 0;
  int b = 0;
  int d = 0;
  int a2, b2, d2;
  for (long long int i = 0; i < (long long int)(M); i++) {
    cin >> s >> c;
    if (N != 1 && s == 1 && c == 0) {
      o = 1;
      break;
    }
    if (s == 1) {
      if (a == 0) {
        a++;
        a2 = c;
        if (N == 3) {
          ans += (c - 1) * 100;
        }
        if (N == 2) {
          ans += (c - 1) * 10;
        }
        if (N == 1) {
          ans += (c - 1) * 1;
        }
      } else {
        if (c != a2) {
          o = 1;
          break;
        }
      }
    }
    if (s == 2) {
      if (b == 0) {
        b++;
        b2 = c;
        if (N == 3) {
          ans += c * 10;
        }
        if (N == 2) {
          ans += c * 1;
        }
      } else {
        if (c != b2) {
          o = 1;
          break;
        }
      }
    }
    if (s == 3) {
      if (d == 0) {
        d++;
        d2 = c;
        if (N == 3) {
          ans += c;
        }
      } else {
        if (c != d2) {
          o = 1;
          break;
        }
      }
    }
  }
  if (o == 1) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}
