#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  if (n == 1) {
    if (m == 0) {
      cout << "0";
    } else {
      long long val;
      cin >> val;
      long long num;
      for (long long i = 0; i < (m - 1); i++) {
        cin >> num;
        if (num != val) {
          cout << "-1";
          break;
        }
      }
      cout << val;
    }
  } else {
    if (m == 0) {
      if (n == 2)
        cout << "10";
      else
        cout << "100";
    } else {
      vector<long long> f;
      vector<long long> s;
      vector<long long> t;
      for (long long i = 0; i < m; i++) {
        long long s1, c;
        cin >> s1 >> c;
        if (s1 == 1)
          f.push_back(c);
        else if (s1 == 2)
          s.push_back(c);
        else
          t.push_back(c);
      }
      long long flag = 1;
      vector<long long> ans;
      if (f.size() == 0) {
        ans.push_back(1);
      } else {
        long long val = f[0];
        if (val == 0) flag = 0;
        for (long long i = 1; i < f.size(); i++) {
          if (f[i] != val) flag = 0;
        }
        ans.push_back(val);
      }
      if (s.size() == 0) {
        ans.push_back(0);
      } else {
        long long val = s[0];
        for (long long i = 1; i < s.size(); i++) {
          if (s[i] != val) flag = 0;
        }
        ans.push_back(val);
      }
      if (n == 3) {
        if (t.size() == 0) {
          ans.push_back(0);
        } else {
          long long val = t[0];
          for (long long i = 1; i < t.size(); i++) {
            if (t[i] != val) flag = 0;
          }
          ans.push_back(val);
        }
      }
      if (flag == 0)
        cout << -1;
      else {
        for (long long i = 0; i < ans.size(); i++) cout << ans[i];
      }
    }
  }
}
