#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  pair<int, int> p[M];
  map<int, int> mp;
  bool exist = true;
  string S[N], T, R;
  for (int i = 0; i < M; ++i) {
    cin >> s[i] >> c[i];
    p[i] = make_pair(s[i], c[i]);
    S[s[i] - 1] = toString(c[i]);
    ++mp[s[i] - 1];
  }
  int tmp = 0;
  int one_num = 0, ten_num = 0, hum_num = 0;
  if (N == 1) {
    for (int i = 0; i < 9; ++i) {
      one_num = i;
      tmp = i;
      exist = true;
      for (int j = 0; j < M; ++j) {
        if (tmp != c[j])
          ;
        exist = false;
      }
      if (exist) {
        cout << i << endl;
        return 0;
      }
    }
  } else {
    if (N == 2) {
      for (int i = 10; i <= 99; ++i) {
        tmp = i;
        one_num = tmp % 10;
        tmp = i - one_num;
        tmp = tmp / 10;
        ten_num = tmp;
        exist = true;
        for (int j = 0; j < M; ++j) {
          if (s[j] == 1) {
            if (c[j] != ten_num) {
              exist = false;
            }
          }
          if (s[j] == 2) {
            if (c[j] != one_num) {
              exist = false;
            }
          }
        }
        if (exist) {
          cout << i << endl;
          return 0;
        }
      }
    } else {
      if (N == 3) {
        for (int i = 100; i <= 999; ++i) {
          tmp = i;
          one_num = tmp % 10;
          tmp = tmp / 10;
          ten_num = tmp % 10;
          tmp = i - ten_num * 10 - one_num;
          hum_num = tmp / 100;
          exist = true;
          for (int j = 0; j < M; ++j) {
            if (s[j] == 1) {
              if (c[j] != hum_num) {
                exist = false;
              }
            }
            if (s[j] == 2) {
              if (c[j] != ten_num) {
                exist = false;
              }
            }
            if (s[j] == 3) {
              if (c[j] != one_num) {
                exist = false;
              }
            }
          }
          if (exist) {
            cout << i << endl;
            return 0;
          }
        }
      }
    }
  }
  cout << -1;
  return 0;
}
