#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, a[N], m;
pair<int, int> arr[N];
int main() {
  cin >> n >> m;
  int mx1 = 0, mn = 1e9;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mx1 = max(mx1, a[i]);
    mn = min(mn, a[i]);
  }
  if (m == 0) {
    if (n > 1) {
      cout << mx1 - mn << endl;
      cout << 0;
    } else {
      cout << 0 << endl;
      cout << 0;
    }
    return 0;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    arr[i] = make_pair(x - 1, y - 1);
  }
  int mx = -1e9;
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    vector<int> temp;
    int sum = a[i];
    for (int j = 0; j < n; j++) {
      sum = a[i];
      temp.clear();
      int val = a[j];
      for (int k = 0; k < m; k++)
        if (arr[k].first <= j && arr[k].second >= j)
          if ((arr[k].first > i || arr[k].second < i)) {
            temp.push_back(k + 1);
            val--;
          }
      sum -= val;
      if (mx < sum) {
        ans.clear();
        ans = temp;
        mx = sum;
      }
    }
  }
  cout << mx << endl;
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  return 0;
}
